tags:

views:

185

answers:

5
+1  A: 

One from top of my head - C++ does not support default int.

dark_charlie
+9  A: 

The elephant in the room: the following is valid C but not valid C++.

int typename = 1;

Substitute your favorite C++ reserved word.

Konrad Rudolph
Whyever was this downvoted?
Konrad Rudolph
+5  A: 

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;
Alexander Rafferty
You might want to clarify that `n` is a variable, not a constant, otherwise it would indeed be valid in C++.
Andreas Magnusson
I would replace `new int[]` and `delete[]` with `std::vector<int>`.
FredOverflow
Can you explain why it is that you can do the first in C? Would `array` be allocated on the stack somehow, and what if `n` were too large for that? I don't know C well at all, and I'm curious what exactly is going on there.
notJim
variable length arrays were added in C99.
Vijay Mathew
@notJim: yes, `array` would be allocated on the stack. If `n` were too large for that then if you're lucky the implementation terminates due to a signal (or other OS-driven sanction). If you're unlucky, the implementation blindly carries on trashing someone else's memory. Depends on the the OS/compiler.
Steve Jessop
That is **NOT** how you would do it in C++.
Martin York
+2  A: 

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 really int f(...). Declare as int f(void) if you don't want f to take parameters.

Alexandre C.
No, `int f()` is not really `int f(...)` , there's a big semantic difference. In the first case, this means I don't know the parameters of that function and at the first encounter of the function call, the default types used as parameters declares the signature of that function, subsequent calls must adhere to that implicit prototype and the compiler should warn if you call the function with other params. With the ellipse it's not the case, each call can have different parameters without warning.
tristopia
@tristopia: Whatever it is, it's really a *don't do this* thing.
Alexandre C.
Absolutely, I was just nitpicking as there is a real but subtle difference. This said I haven't downvoted your contribution as the message is mainly ok.
tristopia
+3  A: 

There is a special wiki entry that summarizes a lot of issues.

Jens Gustedt