• Lucid Dreaming - Dream Views




    Page 1 of 7 1 2 3 ... LastLast
    Results 1 to 25 of 165
    1. #1
      .. / .- –– / .- .-. guitarboy's Avatar
      Join Date
      Sep 2008
      LD Count
      Over 9000
      Gender
      Location
      Homeward Bound
      Posts
      1,571
      Likes
      49

      Tell me about C/C++

      (I know you want to, ninja)
      Well, teach me. I have a compiler and I have basic knowledge, but I'd like to know more before I decide to take courses.

    2. #2
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      (\_ _/)
      (='.'=)
      (")_(")

    3. #3
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      int main()
      {
      int a, b;
      int result;

      a = 5;
      b = 4;
      a = a + 1;
      result = a - b;

      cout <<result<<endl;
      }

      It might look really confusing at first, but when you actually sit down and read it slowly, it's pretty easy to understand.

      In the code I provided, I'm saying that a = 5 and b = 2, then I'm taking a and adding 1 to it, then taking the new answer of a and subtracting it from b which would give me 2.

      I just started learning yesterday :3

      I'm using code::blocks for my C++ writing along with the www.cplusplus.com website.

    4. #4
      .. / .- –– / .- .-. guitarboy's Avatar
      Join Date
      Sep 2008
      LD Count
      Over 9000
      Gender
      Location
      Homeward Bound
      Posts
      1,571
      Likes
      49
      Should I learn C or C++ first?

    5. #5
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      I'm learning C++ to learn how to make my own game engine. I don't really know anything about C.

    6. #6
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      either, really
      they're 80% the same
      (C++ started out as an extension to C)

      depends if you prefer procedural or object orientated programming
      (\_ _/)
      (='.'=)
      (")_(")

    7. #7
      khh
      khh is offline
      Remember Achievements:
      1000 Hall Points Veteran First Class
      khh's Avatar
      Join Date
      Jun 2009
      Gender
      Location
      Norway
      Posts
      2,482
      Likes
      1309
      Well, it depends on what you want to do with it. C++ is better for large projects, while C is best if you're writing time-critical applications. C would also be the logical choice if you want to make other things than computer programs, like if you want to program other integrated chips.
      Many hold that you should always learn C first and then move on to C++, as C++ almost is a superset of C, but either way knowing one will help you with the other.
      April Ryan is my friend,
      Every sorrow she can mend.
      When i visit her dark realm,
      Does it simply overwhelm.

    8. #8
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Quote Originally Posted by khh View Post
      Many hold that you should always learn C first and then move on to C++
      I disagree with that

      There's certain things that are the "right way" in C, but the "wrong way" in C++ (and vice versa)
      Arrays being the biggy

      You may fall into the trap of using wrong methodologies in either language
      (\_ _/)
      (='.'=)
      (")_(")

    9. #9
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Quote Originally Posted by Ynot View Post
      There's certain things that are the "right way" in C, but the "wrong way" in C++ (and vice versa)
      Arrays being the biggy
      Arrays are exactly the same in C and C++.

      He's right about the right and wrong ways being different in C and C++

      Critical section in C
      Code:
      void CriticalMethod(void){
         pthread_mutex_lock(somelock);
         //some critical stuff
         if (boolean){
            pthread_mutex_unlock(somelock);  //have to unlock in every exit path
            return;
         }
         //more critical stuff
         pthread_mutex_unlock(somelock);
      }
      Critical section in C++
      Code:
      //Autolock.h
      struct AutoLock{
         public:
            AutoLock(pthread_mutex_t * lock){
               pthread_mutex_lock(lock);
               mylock = lock;
            }
            ~AutoLock(void){
               pthread_mutex_unlock(mylock);
            }
         private:
            pthread_mutex_t mylock;
      }
      Code:
      void CriticalMethod(void){
         AutoLock lock(somelock);  //will automatically unlock when it returns
         //some critical stuff
         if (boolean){
            return;
         }
         //More critical stuff
      }

      ***********************


      What exactly would you like to know guitarboy, honoured you came to me

      I learned C first, then taught myself C++. I would recommend just learning C++, most programming is done in C++, and it's a lot easier. It's also a good thing to understand object oriented programming.

      Here's some things to understand, in order
      Primitive types: int, long, float, char
      Scope
      methods and functions
      pass-by-reference vs pass-by-value
      const
      Pointers
      Objects (classes and structs)
      Constructors and destructors

      Feel free to IM me about anything
      Last edited by ninja9578; 01-08-2010 at 01:00 AM.

    10. #10
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Quote Originally Posted by ninja9578 View Post
      Arrays are exactly the same in C and C++.
      I know they are the same
      but they're hailed in C, and frowned upon in C++

      From the man himself
      http://www2.research.att.com/~bs/bs_faq2.html#arrays
      (\_ _/)
      (='.'=)
      (")_(")

    11. #11
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Oh, okay, you meant that in C++ you're supposed to use STL containers We still use arrays for various things though.

    12. #12
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      Actually I have a question...

      I'm learning C++ and right now I'm reading about ++ and --

      The example it gives me is this...

      Example 1:
      Code:
      B=3;
      A=++B;
      // A contains 4, B contains 4
      Example 2:
      Code:
      B=3;
      A=B++;
      // A contains 3, B contains 4
      I don't really understand the whole ++ and -- and how it affects the A and B variables. Can someone explain how it adds up?

      Edit: Also, how does all this make up a video game engine?
      Last edited by slayer; 01-08-2010 at 01:41 AM.

    13. #13
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      increment and decrement
      (Ie. add one, or subtract one)
      used all the time when looping and keeping count of things

      a++ means "return the value of a, and then increment it"
      ++a means "increment a, then return the value"

      subtle (but important) differences, however the differences between the pre & post incrementation are only important if you care about the value of a variable mid-operation

      Code:
      for (i = 0; i < max; i++)
      {
      
      }
      and
      Code:
      for (i = 0; i < max; ++i)
      {
      
      }
      are identical in operation
      (because we do not care about the value of 'i' mid-operation

      however,
      say we are keeping a count of something that we later need to step back through in reverse

      Code:
      void increment_something(int var)
      {
          old_var = var++;
      }
      here, we do care about the value of var mid-operation, therefore we store the "old value" of var and increment var

      You can of course do this
      Code:
      void increment_something(int var)
      {
          old_var = var;
          var++;
      }
      then we've split the operation into two
      and now we no longer care about the return value of the increment
      (\_ _/)
      (='.'=)
      (")_(")

    14. #14
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Quote Originally Posted by Ynot View Post
      Code:
      for (i = 0; i < max; i++)
      {
      
      }
      and
      Code:
      for (i = 0; i < max; ++i)
      {
      
      }
      are identical in operation
      (because we do not care about the value of 'i' mid-operation
      Almost correct. In for loops you want to do the latter because in order to return, then increment, it has to keep a copy of it. Not a problem with ints, but with objects it can.

      ++ and -- are weird to learn.

      b = ++a; is like this:
      a = a + 1;
      b = a;

      b = a++; is like this:
      b = a;
      a = a + 1;


    15. #15
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      Err...you're using some things in there I haven't learned yet. So I think you just made it more confusing for me...

      Edit: Ok that makes it a little easier to understand...

      So would it be something like this for the 2nd part?

      b = 1;
      b = a++;

      Would the result be: b = 1, a = 2? Because I already defined b to equal 1 and then a equals b which is 1, then I add a to a to get 2, right?
      Last edited by slayer; 01-08-2010 at 02:08 AM.

    16. #16
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      follow a tutorial on C++
      I've always liked this one
      http://www.cprogramming.com/tutorial/lesson1.html

      It'll take you through the basics, and slowly build up to more complex things

      *edit*
      Just realised you're not the OP.....
      (\_ _/)
      (='.'=)
      (")_(")

    17. #17
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      Lol no I'm not

      But I'll make good use of this thread...

      Also, I'm following this tutorial so far: http://cplusplus.com/doc/tutorial/operators/

      edit: but again, how does all this make up a video game engine? Or any program?

    18. #18
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Well, we break it up. We break down the seemingly huge task of a full program and break it down into pieces which are more manageable. We then code each part, sometimes sticking the together in one executable, but more commonly, we create a complex set of dynamic libraries.

      A video game engine would probably be about a quarter of a million lines of C++ code, broken up into maybe 1000 different files.

    19. #19
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      Wow...quarter of a million...

      Well I guess that adds up fast seeing how small lines of code are.

      A Roxxor wants me to make a simple text based game. I'm not sure how I'm going to do this...

    20. #20
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Well, Most of use consider lines of code as actually newline characters, including white space and comments.

      What kind of game?

    21. #21
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      hangman is always a good first game

      pick a random word from file of possible words
      let the user guess letters
      print letters found, and underscores for not found
      keep a count of num guesses
      (\_ _/)
      (='.'=)
      (")_(")

    22. #22
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      Quote Originally Posted by ninja9578 View Post
      What kind of game?
      Just a simple text based game. Maybe something like, "You grab a gun. What do you do next? Respond: Shoot the enemy. The enemy dies."

      I'm not really sure if that's how it's going to be though...

      I'm wanting to make my own game engine and A Roxxor said he would help me out. We're going to be working on a 2D side scrolling platformer. I have all the ideas in my head and some of it's written down.

      I think he said he's going to be working on the level editor and I'll be learning C++ and helping Drawsher with working on the sprites for the characters.

    23. #23
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Oh oh oh, I'm doing that too. I'm calling my game Mavio. I've got the shell of it all done, I just need to fill in my code out with the functionality

    24. #24
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      the way to plan out a programming project is to start with a large idea and break it down into lots of smaller segments
      then break those segments down further, and so on

      You should end up with tons of really simple operations that are a doddle to code

      Code:
      void player::take_damage(int damage)
      {
          player.health -= damage;
      
          if (player.health < 0)
          {
              died();
          }
      }
      (\_ _/)
      (='.'=)
      (")_(")

    25. #25
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      So far all I've learned how to do is this:
      http://img503.imageshack.us/img503/2765/67539020.jpg
      Which comes out to be this:
      http://img99.imageshack.us/img99/6329/69704121.jpg

    Page 1 of 7 1 2 3 ... LastLast

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •