#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++.

The following program will print a different value for a depending on whether it is compiled in C (pre C99 standard) or C++

#include <stdio.h>
void main()
{
   int a;
   a=4//**/2;
   ;
   printf("%d\n",a);
}

The reason being that traditional C reads the line as a=4/2; with a comment in the middle. C++ (and C99) comments out the whole line after the 4, and uses the following semicolon to end the line.

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