How different is C from C++ ?

Started by
5 comments, last by jbadams 17 years, 6 months ago
OK, I have been eye balling that book called Beginning Game Programming by J.S. Harbour and he says that you will need to know the basics of C. I already have Beginning C++ Game Programming by Michael Dawson and I have been reading it for a while taking my time and moving along little at a time grasping everything with a firm grip over the understanding of some of the more uterly complicated things. I also want to buy this other book because it does everything not just a language, so can I jump into it with basic knowledge of C++ or not? please explain how different are the two languages?
Advertisement
The differences between C and C++ are usually minor. If you are familiar with classes in C++ then you'll notice that they're missing. new and delete are replaced with malloc() and free().

In short, you'll be fine.
Hmm, lets see..

new/delete -> malloc/free
templates -> macros
std::vector -> void*
std::string -> char*
functors -> function pointers
classes -> POD structs
member functions -> global functions
namespaces -> name prefixes
iterators -> pointers
inheritance -> ?
polymorphism -> ?
metaprogramming -> ?

Other than that C++ and C are pretty much the same.

[Edited by - deathkrush on October 1, 2006 1:49:26 AM]
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
templates → a small subset of the functionality can be performed by macros. A large amount of other details (specialization, ease of debugging, ...) have to be handled in other, more imaginative ways.

std::vector → T[], for any type. If you wish to use dynamic arrays, T*, preferably as part of an opaque type.

functors → closures (void* data and function pointer)

classes → opaque types

member functions → global functions operating on opaque types

destructors → one delete per base object type, which calls the embedded destructor and releases the memory, or use objects that do not require destructors.

inheritance → opaque type parametric initializers

polymorphism → opaque types with member functions

metaprogramming → external metaprogramming language/code generator

T& → T*

const T x = y; → #define x y
I got some nice advice about switching from C++ to C just the other day ago in this thread. Mabye you'll find some of it usefull to keep in mind.
Ok, I'm not really swtiching I just have a desire to buy this book since it covers the basics of everthing. So I can keep learning C++ and buy this book and I'll be good?
Yes. They're different languages (despite the popular misconception that C++ is a sort of "C with extras") and are programmed in different styles, but if you understand the basics of C++ you shouldn't have any major difficulties with a book that requires a basic understanding of C. Just keep in mind that the thought process may be somewhat different at times, look up anything you don't understand and you should be fine with it.

It would actually be quite a good way to test and solidify your understanding to convert the concepts taught into a more C++ way of thinking as you go if you feel up to it.

- Jason Astle-Adams

This topic is closed to new replies.

Advertisement