Can we make 'C' in gcc/g++ and clang/clang++ as a subset of C++ compiler as such g++ would compile files .c extension as such all functions would be treated 'extern C' automatically and consider all C++ specific keywords context sensitive. These would help migration of C program to C++ painless and/or use of C++ goodies painless without forklift update of program written in C. Everything that is considered error in C++ would also be considered error in C (with compiler option to convert these as warning for .c files).
Asked
Active
Viewed 70 times
0
-
1No. You can, however, compile C as C, and then use both C and C++ in the same program. Just don't try to throw an exception through a C stack frame. – Dietrich Epp Jan 24 '14 at 05:02
-
So why wouldn't just compiling the C code with C++ compiler do what you want? Maybe disable some warnings. – hyde Jan 24 '14 at 05:18
-
1The first C++ "compilers" were not compilers, but translators of C++ into C code, which was then compiled - debugging was challenging. So by some definition, anything done in C++ was do-able in C in some fashion - making C++ a subset of C functionality. I suspect today anything done is C could be translated into an equivalent C++ today. It becomes a challenge of how function/variable names from mixed libraries may need some mangling to cooperate as well as other issues. – chux - Reinstate Monica Jan 24 '14 at 05:20
-
Just adding `extern "C"` isn't sufficient to "fixup" all C. Consider `void class(void);`. – Flexo Jan 24 '14 at 07:36