Jump to content
  • Advertisement
Sign in to follow this  
Peter Stephenson

C vs C++

This topic is 4733 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

Ive been programming for a few years now and consider myself to be a reasonably strong intermediate programmer. I am trying to teach myself game development (with the help of a few books) and have a question that I would like answering if possible (I apoligise if this has been asked b4 i usually search forums but the search is down) Which is better to use? the procedural and structure based approach of C or the Object Oriented development of C++ im concerned with both efficiency of the method of programming and with the ammount it is used in the industry as well as any other important factors Any help with this would be appriciated Thanks Peter

Share this post


Link to post
Share on other sites
Advertisement
I think it all ultimately comes down to your own preference.
Play with both and you will find what you are most comfortable with.

I personally prefer C++ (started with C then moved on to C++) with the OO approach but there are benefits in both camps...

All I can really say is try both and see how you go.

Share this post


Link to post
Share on other sites
To be honest I'm not sure
I think that after its all been compiled it has a negligable difference. I know the time and true saying that gets dismissed is what follows but its true. On todays systems the difference is not going to matter unless you are making software for embeded (sp?) systems.

Share this post


Link to post
Share on other sites
Quote:
Original post by Peter Stephenson
does using inheritance have an impact on performance? (i know the use of virtual functions does but other than that?)

Inheritance doesn't impact performance itself, virtual functions which make an important part of inheritance does however theoretically do this.

Know what kind of code your compiler generates before starting to talk about performance issues on this kind of level. The little extra time it takes to do two lookups and a indirect call is irrelevant for a virtual function call is in 99% of the time irrelevant.

Using the correct data structures and algoritms is the key to getting maximum performance, focus on that instead.

Share this post


Link to post
Share on other sites
To be brutally honest: if you have to ask this question, you're not an intermediate programmer. Well, you might be an intermediate programmer, but you're still a beginner software engineer.

Languages are tools; each one has situations in which it excels, and situations in which it falls apart. Your question is akin to "Which is better, a wrench or a screwdriver?" It depends entirely on what you plan to use it for. ("Developing games" isn't a valid answer, because both languages are suitable for different parts of different kinds of game - to extend the metaphor, it's like "For building a house.").

C gives you very low-level control and flexibility, at the cost of ease of use. C++ gives you less control, but most people find it easier to 'think in objects.' The language isn't important - decide whether you want a purely procedural method of development, or whether you want object-oriented. Once you've made that decision, consider that C and C++ are not the only language of each type.

And no, inheritance has no effect on performance beyond your aforementioned point of virtual functions (which takes two extra instructions to call).

Share this post


Link to post
Share on other sites
1. OO is no panacea, its only suited to a set of problem domains for example it excels in GUI frameworks.

2. If you only focus on OO your being closed minded and restricting yourself, its like you only have a hammer to build everything.

3. Traditional OO is typically not enough, you will most likely find yourself using Post-OO and a mix of paradigms.

4. Saying "I prefer OO over procedural" is nonsensical as in essence OO is merely an extension of the concept, it does not try to solve the problems of procedural programming.

5. You can do OO in C.

6. C++ is not merely an OO language, its not "just C with OO" its a multi-paradigm language, natively you can do procedural, OO, generic, generative, pure functional programming (at compile-time when doing template meta-programming). With libraries you can also do some form of functional too.

7. Your worrying about the wrong kind of efficiency, choosing more efficient algorithms & data structures for the job is more important.

[Edited by - snk_kid on June 9, 2005 3:19:00 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Peter Stephenson
Which is better to use?
the procedural and structure based approach of C
or the Object Oriented development of C++

The best is obviously to have both available, so you can use what makes sense to use.

C++ is a superset of C, so in other words, use C++, and then write code using whatever approach is best suited. If you feel OO would be a waste of time for your particular problem, then write it "C-style" instead.

(And yes, you can do OO in C. You can also do functional programming in C, if you like. But languages which explicitly support are still better suited for it. In the same way, C++ is better suited for OO.)

Share this post


Link to post
Share on other sites
Quote:
Original post by Spoonbender
C++ is a superset of C


As of this moment its not quite, standard C++ does not incorporate some of the additions mades to C99 like restrict pointers but i do know what your trying to get at.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!