Advertisement

C or C++?

Started by April 22, 2002 04:42 PM
10 comments, last by Seifer 22 years, 8 months ago
I often hear that C++ adds an extra overhead with classes and that many games are programmed in plain C. I''m currently learning C++ but I was wondering, should I aslo be proficient in C (ie learn the procedural way)? Will all games be programmed in C++ eventually?
I hate signatures.
quote: Original post by Seifer
I often hear that C++ adds an extra overhead with classes and that many games are programmed in plain C. I''m currently learning C++ but I was wondering, should I aslo be proficient in C (ie learn the procedural way)? Will all games be programmed in C++ eventually?


Some of the mechanisms available to you through classes (e.g. virtual functions) have an overhead cost. But implementing the same mechanisms in C would give you the same (or worse) overhead. Objects with expensive constructors will be expensive to instanciate. Same in C, if a data structure requires expensive initialisation.

Yet, C++ has features which are actually more efficient than the C equivalent (case in point: sorting with an inlined predicate, as opposed to using qsort() with a function pointer). Do learn to use the Standard Template Library. It contains better code than most of us can write.

The point is to know exactly what features are costly and where/when to use them or not. That''s at least as important as knowing the language itself.

Now, to actually answer your question, knowing C does no harm. After all, the C library is also part of the C++ library, and C++ can very well be used as a "better C", without ever using a single class.

[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]

Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
I hate signatures.
It''s probably a good idea to start with C. As Fruny said, C is a subset of C++ (all that you can do in C you can do in C++) so learning it first won''t harm you in any way. In my opinion C is easier to learn for a beginner than diving right into C++ (then again it''s just my opinion). Also it''s good to know the straight up C because things like handhelds use it. GBA uses C for instance.
There are so many "Should I use C or C++?" threads out there...

I am governed by none other than the Laws of the Universe.
"I am governed by none other than the Laws of the Universe."
quote: Original post by Supernova
It''s probably a good idea to start with C. As Fruny said, C is a subset of C++ (all that you can do in C you can do in C++) so learning it first won''t harm you in any way. In my opinion C is easier to learn for a beginner than diving right into C++ (then again it''s just my opinion). Also it''s good to know the straight up C because things like handhelds use it. GBA uses C for instance.


It''s too late, I already like the concepts of OOP so I''m into C++. I admit those concepts add extra difficulty though. Anyway, I''m only at the "C with classes" point for now. I''m not aiming for handhelds but I guess I''ll know C when I get into the industry.

quote: i8degrees
There are so many "Should I use C or C++?" threads out there...


If by "out there" you mean outside of gamedev, I''ll say I''m not interested in developing normal software.
I hate signatures.
Advertisement
Personally, I believe that C++ is an excellent second language. Exposure to a fairly restrictive beginner''s instruction language like BASIC or Pascal is a good way to learn the fundamental concepts of programming, and after that migration to C++ and absorption of OO principles.

quote: Original post by Seifer
If by "out there" you mean outside of gamedev, I''ll say I''m not interested in developing normal software.

No, he means here on GameDev. You can use the search feature to find and check them out.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!
i agree too....

i had learn pascal , cobol and C before getting into C++..

COBOL trivia. Did u know that cobol was created by a grasshopper ????

{ Stating the obvious never helped any situation !! }
quote: Original post by jwalker
COBOL trivia. Did u know that cobol was created by a grasshopper ????

Grace Hopper == grasshopper? As a pun/joke, this must be one of the worst I have heard in a long while.



--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
quote: Original post by Oluseyi
Personally, I believe that C++ is an excellent second language. Exposure to a fairly restrictive beginner''s instruction language like BASIC or Pascal is a good way to learn the fundamental concepts of programming, and after that migration to C++ and absorption of OO principles.


I learned some kind of BASIC on a Texas Instrument calculator. All integer variables were predefined and global, which led to pretty ugly and hard to maintain code, but I had no problem with control flow when I switched to C++. The OO approach is surprising at first because it tends to mimic the real life semantics.

quote: jwalker:
COBOL trivia. Did u know that cobol was created by a grasshopper ????


Was that a Jay Leno question?
I hate signatures.

This topic is closed to new replies.

Advertisement