This has just come up as a question where I worked so I did a little digging and the answer is a ExpertsExchange one. So I hand you over to the original question asker, Manchung:
I have a project written in pure C which is to be used in embedded system. So, I use pure C to minimize the code size.
When I compile the project, I use the -ansi flag in order to make sure the code complies with the ANSI standard. However, the down side of using this ansi flag is that I am only allowed to use C styled comments (/*comments */). This is giving me a headache when I need to use nested comments.
So, my question is: what switches/flags can I use to allow me to use C++ styled comments (// comments) while keeping the ANSI checking enabled at the same time?
Which pretty much sums my question up too.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With