Rob Hoelz wrote:
I've been compiling a list of the differences between C and C++, and
I'd like to see how thorough I've been. Could any of you go over this
list and see if I've missed anything?
Here's the list:
Mid-scope declarations
Default function parameters
new/delete operators
Better implementation of const
References
Exception handling
"Catch all" catch block
All catches are a difference from C... isn't the above line redundant
with the preceding line?
Classes
Constructors/Destructors
Access modifiers
Inheritance (multiple inheritance too)
Templates (classes and functions; template specialization)
Initialization Lists
Implicit constructors
Friend access
Namespaces
Anonymous unions
Better casts (type) type(var) static_cast<typeconst_cast<type>
reinterpret_cast<typedynamic_cast<type>
Inline functions
Enhanced static
Member function/data pointers
Virtual functions (pure)
Const pointers
mutable keyword
Anonymous namespaces
You don't need struct, union, enum tags
:: (scope resolution operator)
Function overloading
Operator overloading
Runtime type identification
C++ style includes
// Comments
Functions as an l-value (must return reference)
structs can include functions
As may unions.
this pointer
bool keyword (is it a C++ keyword?)
Yes, it's a keyword in C++.
I/O mechanisms
That description's pretty vague... obviously C has I/O mechanisms...
STL
This is more of a list of differences between the 1990 version of C and
C++, rather than differences between C (which is now defined by the
1999 standard) and C++. If it were the latter, differences such as //
comments, bool (though it's not a keyword in C), inline functions, and
"Mid-scope declarations" would go away (though there would still be
some related differences). New differences such as C's "restrict"
keyword, compound literals, C's complex number implementation, and
Variable Length Arrays would need to be listed.
Here are some further differences between C90 and C++ that spring to
mind:
Removal of non-prototype function declarations.
Removal of implicit int (also removed from C99)
The type of string literals (const char[] vs char*)
The type of character literals (char vs int)
Implicit conversion to/from void* has been removed.
main() cannot be called recursively in C++ (can in C)
Conversion between object pointers and (unsigned char *) is not
explicitly well-defined as it is in C
.... if you really want to be pedantic about such differences, you could
sit the C and C++ language specifications side-by-side, and compare
differences in related sections. That would take quite a while, but you
could end up with a pretty exhaustive list that way :)
-Micah