Can I assume that if a .c file compiles ok with gcc it will also compile
ok with a .cc extension with g++ ?
No.
Any example where this does not work ?
Obvious example:
int old,new; /*Valid C, invalid C++*/
More subtle example:
--------
#include <stdio.h>
int main(void)
{
int i=42//**/
+7;
if(i==49)
if(sizeof 'a' == 1)
puts("C++ compiler or unusual byte size");
else /* // comments and 'a' is int*/
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
puts("C99 compiler");
#else
puts("broken C89 compiler");
#endif
else
puts("C89 compiler");
return 0;
}
--------
dave@goofy:~/clc (0) $ gcc test.c
dave@goofy:~/clc (0) $ ./a.out
broken C89 compiler
dave@goofy:~/clc (0) $ gcc -ansi test.c
dave@goofy:~/clc (0) $ ./a.out
C89 compiler
dave@goofy:~/clc (0) $ gcc -std=c99 test.c
dave@goofy:~/clc (0) $ ./a.out
C99 compiler
dave@goofy:~/clc (0) $ cp test.c test.cc
dave@goofy:~/clc (0) $ gcc test.cc
dave@goofy:~/clc (0) $ ./a.out
C++ compiler or unusual byte size
dave@goofy:~/clc (0) $