Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

v0dKA

C++ VS C

This topic is 5224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Another language vs. language post, sorry. I normally program in C++. I''m starting to learn actual game programming now, with Direct-X (Made it out of DOS-World, finally). However, my current game programming resource (Windows Game Programming with Direct X, by Andre LaMothe) uses C, and warns the user that their knowledge of C++ can be almost null, as long as they know C. This didn''t make me put the book down and learn C, or throw the book out and buy a C++ game programming book instead. I actually started wondering if C was better/faster. For game programming in particular, is C actually better (or faster)? Also, how close is C to C++? Will I be overly confused to death, or...
.:<<-v0d[KA]->>:.

Share this post


Link to post
Share on other sites
Advertisement
Just pretend it''s C++, it should compile. And null doesn''t really exist in C++, so if he''s trying to relate to C++ programmers by using that term, he failed miserably.

Share this post


Link to post
Share on other sites
He's trying to relate to the C users because it's saying they don't need to know C++

Remember everything in C works in C++ and most stuff is pretty common sense if you only know C++. I don't think it will hinder you too much.

BTW: Putting two languages and/or "vs" in the topic title is a good way to get 90% of people to automatically hate you or not even read it.

[edited by - Ceoddyn on June 4, 2004 12:00:34 AM]

Share this post


Link to post
Share on other sites
If you know C++, you know 90% of what you''ll use of C. (mostly missing out on optimization opportunities and the like)

If you know C, you know about 50% of what you''ll use of C++. (mostly focused on oo design).

So far as speed is concerned, a function compiled under C++ will perform the same as a function compiled under C 99% of the time.

C has a very slight speed advantage in the sense that your functions won''t be encapsulated within a class, which removes the accessor overhead.

This overhead is extremely minimal, and if you consider it a reason not to use C++, you have very poor criteria for language selection.

Any programmer worth their salt will always know "C/C++", not "C" or "C++". You should be able to read code written in either language and not think twice about it''s implementation.



Share this post


Link to post
Share on other sites
quote:
Original post by Etnu
Any programmer worth their salt will always know "C/C++", not "C" or "C++". You should be able to read code written in either language and not think twice about it''s implementation.



I hope you mean "know C and C++ not C or C++". They are seperate languages that can''t even agree on what const means, although the two are related. Also, not all valid C code that follows recommended practices compiles in C++. C99 diverges even further.

All right, I''m done with my pedantic nitpicking. Now, to address the OP, use C++ for game programming.

Most tutorials for game programming are in C++, those that aren''t tend to be in C that wouldn''t cause much trouble for a C++ programmer who knows the difference between string.h, string, and cstring.

C may have a slight edge in speed since "good C" tends to be closer to the metal than "good C++", but if you absolutely need to micro-optimize, then you can always drop to a more C-like style in C++. (hint: turn on optimizations and look for a better algorithm before micro-optimizing)

As for which is better, the correct response is "better for what?". I use C both because I believe it''s better for my purposes and because I prefer it personally.

So, my advice to you, would be to stick to C++.

Share this post


Link to post
Share on other sites
quote:
Original post by v0dKA

However, my current game programming resource (Windows Game Programming with Direct X, by Andre LaMothe) uses C, and warns the user that their knowledge of C++ can be almost null, as long as they know C.

This didn''t make me put the book down and learn C, or throw the book out and buy a C++ game programming book instead. I actually started wondering if C was better/faster. For game programming in particular, is C actually better (or faster)?



Lamothe codes in a C style in that book, but is actually using C++. Notice the files all have .cpp extensions, and in some places he uses C++ specific features (such as references). Don''t let it throw you off.

As to which is faster, does it really matter? In terms of raw performance you can likely wring more out of the processor with C. But on the whole the difference is so not worth considering.

And never ask which language (any language) is better. I prefer C and Java to C++, because I''m experienced and comfortable with both. In my opinion, C++ has the most bloated specification of any other language out there, and it''s biggest failing is that it caters to several different programming paradigms/styles (something others see as its greatest strength). So I would definitely say C is better - but that''s for me, and I wouldn''t want to convince you of it.

I''d suggest that if you want to know how a language rates, just roll your sleeves up and get some pratical experience with it. Don''t be one of those poor sods who take the usually biased and/or unfounded/uneducated opinions of the forum blabbers as gospel. You will never, ever, find agreement and you will never grow.

Share this post


Link to post
Share on other sites
quote:
Original post by Ceoddyn

BTW: Putting two languages and/or "vs" in the topic title is a good way to get 90% of people to automatically hate you or not even read it.

[edited by - Ceoddyn on June 4, 2004 12:00:34 AM]


It''s a flame bait - works preaty good at geting atention (at least in my case)

If you know how to use C++ you will be able to use C (there is a diference in stuf like ''&'' - ''*'' for pointer declaration and similar) buth the C++ is actualy C with classes - this is writen in almost every book I hawe seen about C/C++.

Also if you know C++ good you will hawe no dificulties reading the book.

And I think tehe reason the book was writen in c and not c++ is becouse C is easy to read (easyer than C++ for me at least)

Share this post


Link to post
Share on other sites
Andre LaMothe is an odd bloke...he says he writes in C in his books, but then uses structs with functions in them...also known as classes. Fact of the matter is that if your doing windows programming, whether you do C or C++ you are going to use the same compiler (VC++) because it optimizes the best...personally I''d say just learn C++...it is easier to go back from C++ to C than the other way around...people like poor Andre there are STILL struggling with going from C to C++, the other way is no struggle at all.

Share this post


Link to post
Share on other sites
If you know C++ I think you could be fine workign with that book since I heard it is C mixed with C++. The language features aren''t that different. But I have as much experience programming with C as with C++ about a year only that''s not much but what''s excepted in C++ isn''t alwys in C and vice versa. C++ supports many types of programmign while C isn''t OOP. A standard C Program will look different from a standard C++ program in terms of style and some other things like memory call, location of variable decleration.

But you can code C in C++ so you should be able to just code it and run it, besides it''s a game programming book, if it''s any good(I don''t have to book just read some sample chapters) you should be able to use the concepts learned with any language.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!