display | more...

#include <stdlib.h>
#include <stdio.h>

int main()
{
  int *new = malloc(10*sizeof(*new));

  printf("The address of new is %p\n", (void*)new);

  return EXIT_SUCCESS;
}

Please compile this on your C compiler, with the maximal level of warnings (gcc -pedantic -Wall might be a good place to start). This program is strictly conforming standard ISO C.

Now please try to compile it with your C++ compiler, with the maximal level of warnings (g++ -pedantic -Wall is a nice try, although it will accept both includes, which strictly speaking are deprecated in ISO standard C++, either). I count 3 corrections required to make it into a horrible but conforming C++ program.

C != C++

(no, that's not legal C OR C++...)

The noder known as ISO C. Gorgonzola points out it is legal C and legal C++. Just that its value is undefined by both ISO C and ISO C++.

Log in or register to write something here or to contact authors.