Search code examples
c++cgcccommentsgcc4

How are C++-style comments handled in GCC 4.3.3 by default?


I'm using GCC 4.3.3 on Ubuntu 9.04 64-bit and was getting errors using C++-style comments in C code. When I say "by default" in the title, I mean simply invoking gcc test.c

According to the GCC 4.3.3 docs (here), this is supported...yet I got the errors anyway.

These errors went away with a simple -std=c99 addition to my compile string, so my problem is solved. Curious if any GCC experts out there had an explanation for this, as it seems to me to be a clear contradiction to the documentation.

#include <stdio.h>
// this is a comment

int main( void )
{
   return 0;
}

Solution

  • By defualt GCC is using C89/90 standard with GCC extensions. Strictly speaking by default it is not adhering to any specific standard, since by default it will not issue any diagnostic messages in situations when such messages are required by the standard. You need to run gcc in -ansi -pedantic mode (possibly also -Wall) in order to make it stick to the standard. And in this case you'll have, once again, C89/90.