C++ to C?

Started by
44 comments, last by TerrorFLOP 15 years, 10 months ago
I just finished a beginner C++ book, Beginning C++ Through Game Programming, and just picked up Game Programming All in One. The latter assumes knowledge of C/C++, but is programmed primarily in C. How will I fare with C programs knowing C++ syntax? Should it be fairly easy to pick up? If it helps gauge anything, I'm not really new to programming in general, and have some experience with Java up to manipulating/creating data structures.
Advertisement
Syntax and some common functions are really the only things shared between C and C++. Idiomatic C and idiomatic C++, which you should be writing, are completely different. The "right way" to do something in C and the "right way" to do that same thing in C++ are not necessarily anything alike, and both languages should be considered completely separately.

So no, the only thing you're going to pick up immediately is syntax. That being said, syntax is one of the more annoying parts of either of those languages, so you should be able to pick up the idioms fairly quickly, especially if you have prior experience.
Ra
C++ is the next iteration of C. Literally. All syntax is pretty much the same between the two, minus some cool things:

- C can't do templates.
- C can't do classes, but it has Structs.
- C can't use new/delete off the bat, you have to use malloc/free.
- C doesn't have a bool type.
- C can't do inline variable instantiation such as: for(int i = 0; ...)

But other then those, syntax is pretty much the same.

Take a look at this link:
http://www.cprogramming.com/tutorial/c-vs-c++.html
------------Anything prior to 9am should be illegal.
That being said, which of the 2 languages do you personally feel is easier? Would I benefit by sticking with C after going through this book (in terms of game programming use and industry standards)?
Quote:Original post by hellmel36
That being said, which of the 2 languages do you personally feel is easier? Would I benefit by sticking with C after going through this book (in terms of game programming use and industry standards)?

The language you use now is irrelevant. You don't have to stick with any language, just choose the right tool for the job. C and C++ are used in the industry primarily for historial reasons (i.e. they already have extensive codebases already written in them) rather than anything else.

Personally I think that for any application of reasonable scale you'll want to be using C++, idiomatic C++, instead of C because you can take advantage of things like smart pointers and RAII and all kinds of facilities that'll allow you to write safe, robust code with minimal effort.

But don't give in to the false notion that you need to pick one language and stick with that forever. Good programmers know a number of languages and use each of them regularly where appropriate.
Ra
C is old
C++ is new

If you've learnt or are learning c++ stick with it. Go forward not back.
Quote:Original post by hellmel36
I just finished a beginner C++ book, Beginning C++ Through Game Programming, and just picked up Game Programming All in One. The latter assumes knowledge of C/C++, but is programmed primarily in C. How will I fare with C programs knowing C++ syntax? Should it be fairly easy to pick up?

If it helps gauge anything, I'm not really new to programming in general, and have some experience with Java up to manipulating/creating data structures.


What exactly are you hoping you will gain by learning C now?
Thanks for that bit of advice, Ra. It seems that in the programming world it's almost a good thing to be a "Jack of All Trades", but the "Master of None" part is what I really want to avoid, especially while starting off as a beginner in basically 2 languages that are so similiar.
Quote:Original post by frogtag
C is old
C++ is new

If you've learnt or are learning c++ stick with it. Go forward not back.


I'm only going to be looking at C as it is in the context of this book. It appears to be a really good book, just the concepts are introduced through C for the most part. I figure it can't hurt to learn C. I'm just concerned whether it will hurt to learn it before I have had sufficient experience with C++ (enough to clearly see the difference between the two, anyway).
Quote:Original post by hellmel36
Quote:Original post by frogtag
C is old
C++ is new

If you've learnt or are learning c++ stick with it. Go forward not back.


I'm only going to be looking at C as it is in the context of this book. It appears to be a really good book, just the concepts are introduced through C for the most part. I figure it can't hurt to learn C. I'm just concerned whether it will hurt to learn it before I have had sufficient experience with C++ (enough to clearly see the difference between the two, anyway).


Honestly, it can hurt to learn C. C really has a different programming paradigm than C++, and often, people pick and choose, and mix in parts of the older paradigm that have been corrected.

Quote:
C++ is the next iteration of C. Literally. All syntax is pretty much the same between the two, minus some cool things:

- C can't do templates.
- C can't do classes, but it has Structs.
- C can't use new/delete off the bat, you have to use malloc/free.
- C doesn't have a bool type.
- C can't do inline variable instantiation such as: for(int i = 0; ...)

But other then those, syntax is pretty much the same.

Take a look at this link:
http://www.cprogramming.com/tutorial/c-vs-c++.html

I wouldn't really suggest that link honestly, as it's out of date. C++ isn't the next iteration of C, rather C99 is (just as C++0x is the next iteration of C++). C now supports booleans, and you can declare an object in a for loop.

Also, C++ and C aren't entirely compatible, as what could do one thing in C can do a completely different thing in C++.

While learning a new language may help in the long run, you have to ask yourself if it's worth learning for what you're trying to accomplish.

This topic is closed to new replies.

Advertisement