How do I enable C++ styled comments in gcc while leaving ANSI enabled? How do I enable C++ styled comments in gcc while leaving ANSI enabled? c c

How do I enable C++ styled comments in gcc while leaving ANSI enabled?


On recent releases of gcc, -ansi is documented as being the same as -std=c89. The new comment syntax is only available with the C99 standard, so -std=c99 would allow it.

There is also -std=gnu89, which is the same as -std=c89 but allowing all gcc extensions (including the C++-style comment syntax, which was a GNU extension long before it was added to the standard).

Also look at the -pedantic flag, which could give you some useful warnings.

References:


If you want to use C++ style comments merely because you want to comment out blocks, and get a headache about nesting /* ... */, you can use this technique:

#if 0... code ...#endif

which will actually also do the job.


You can use -lang-c-c++-comments preprocessor to have both ANSI mode and C++-style comments.

gcc -Wp,-lang-c-c++-comments -c source.c