What prevents C++ from being a strict superset of C? [duplicate]
Possible Duplicate:
“C subset of C++” -> Where not ? examples ?
I'm aware that C++ is not a strict superset of C. What language features prevent C++ from being a superset of C?
The elephant in the room: the following is valid C but not valid C++.
int typename = 1;
Substitute your favorite C++ reserved word.
C++ also does not support variable-length arrays, where:
int array[n];
is valid in C, but not C++. A C++ version of the above would be:
int *array = new int[n];
...
delete [] array;
There is a special wiki entry that summarizes a lot of issues.
Simple example, consider this declaration:
int f();
This is valid C, but invalid C++: f(3, 2, -5, "wtf");
Explanation: in C, int f()
is treated like int f(...)
(at least at the first call site). Declare as int f(void)
if you don't want f
to take parameters.
One from top of my head - C++ does not support default int.
精彩评论