TPU ChatChat on IRC
Internet Relay Chat?
Java Applet client
Who's on IRC?
Differences between C and C++
Posted by mrnorman [send private reply] at July 11, 2002, 05:15:45 PM Hey, This souds like something that would surely have appeared on this message board before, but I couldn't find it...so what are the differences between C & C++?
Posted by unknown_lamer [send private reply] at July 11, 2002, 05:28:20 PM C++ has an "object system", templates, slightly stricter typing rules, the ability to implicitly convert between types if (using operator type ()), a different casting system (static_cast<> and friends), exceptions, and a larger standard library than C. C has very weak typing (don't get this confused with dynamic typing; C is a staticly typed system, but those types are easily converted into other types (even where it doesn't make sense) making it weak). C99 also has a few extra types (_Complex, _Bool, _Imaginary, etc) and extra keywords (e.g. restrict) and nice things like variable sized arrays (e.g. int foo; scanf ("%d", &foo); int bar[foo]; will work). A lot of well written C _is_ C++, unless they use the C99 features (C++ is basically compatible with C89). GCC (and probably other compilers) make a lot of the C99 stuff available to C++ anyway (e.g. GCC lets C++ use restrict as __restrict).
Posted by metamorphic [send private reply] at July 13, 2002, 06:51:44 AM in c++ you use the words 'new' and 'delete' to handle memory, in c you use 'malloc' and 'free', C++ has classes and structures, C only has structures. classes can hold functions as well as variables and all variables have default visablity of private. Structures call only hold variables and default visability for the variables is public.
Posted by unknown_lamer [send private reply] at July 13, 2002, 11:51:59 AM Actually, in C++ a struct _is_ a class. It can do everything a class can do (inheritance, methods, etc) except that everything is public instead of private by default (you can always just make stuff private using
Posted by mrnorman [send private reply] at July 13, 2002, 04:19:13 PM haha, thanks CodeRed, just what I was looking for ;-). So basically, the biggest difference is in the class system, memory allocation, type definitions, and (I assume) inheritance. This explains why the win32 api (which claims to be in C) doesn't seem to have any full blown classes in the code, just types and methods and what not. Well, I guess now my question is if it would work to write the win32 api specific stuff like GUI's in strictly C, but write other code that doesn't interact with the win32 api in full C++ (with class declarations and everything).
Posted by metamorphic [send private reply] at July 13, 2002, 06:47:58 PM If you want usefull classes, look at the standard template library. It has some really usfull classes like lists, strings, vectors and a bunch of robust, efficient alorithms.
Posted by RedX [send private reply] at July 14, 2002, 07:33:51 AM C++ can use all good C code. It's common practice to write a wrapper class around C functions. You could write a class to handle all the WIN32 API calls.
Posted by mrnorman [send private reply] at July 14, 2002, 09:08:11 AM ah, that's a more realistic idea, thanks
Posted by unknown_lamer [send private reply] at July 14, 2002, 01:09:46 PM Actually...C99 has several new things that C++ doesn't support, and C99 is still good code (e.g. variable sized arrays) even though the C++ compiler won't accept it.
Register as a new user