4

Possible Duplicate:
What issues can I expect compiling C code with a C++ compiler?

Just curious whether I could make use of a c++ compiler to compile c source code??Anyway is there any compiler that fully support c99 standard yet??

Community
  • 1
  • 1
caramel1995
  • 2,968
  • 10
  • 44
  • 57

3 Answers3

10

C++ is not a superset of C. There are places where they differ, which means some C code will not compile in C++ mode.

As for C99 support, GCC and Clang are the closest. Microsoft does not support C99, and only focuses on C++ (which overlaps with C99 in places).

Yann Ramin
  • 32,895
  • 3
  • 59
  • 82
10

You might have a problem compiling C code with a C++ compiler unless you explicitly restrict the compiler to use C (which all the C++ compilers know how to do). If the compiler uses C++ to compile C code you might have issues if in the C code you use words that are reserved in C++.

For example, C code like this:

int main(void) { int class = 5; return class;}

Will compile fine with a C compiler (or C++ compiler in C mode), but will not compile with a C++ compiler.

feihcsim
  • 1,444
  • 2
  • 17
  • 33
littleadv
  • 20,100
  • 2
  • 36
  • 50
6

The two problems that I can quickly think of (there's probably more) that would arise when compiling C code with C++ is casting and variable names. For example:

char* new = malloc(20);

The above is valid C, but when compiling in C++ you would get the following errors:

  1. char* cannot be assigned to void* without an explicit cast.
  2. new is a keyword.

Yes, some compilers do support C99. GCC probably does, but I only have experience using MSVC and they don't support it.

Marlon
  • 19,924
  • 12
  • 70
  • 101