views:

4648

answers:

2

Hello, I have the source code of an application written in C++ and I just want to comment something using:

#ifdef 0
...
#endif

And I get this error

error: macro names must be identifiers

Why is this happening this?. Thanks

+6  A: 

Use the following to evaluate an expression (constant 0 evaluates to false).

#if 0
 ...
#endif
tvanfosson
+5  A: 

The #ifdef directive is used to check if a pre-processor symbol is defined. It's possible that your C compiler allows pre-processor symbols that start with a digit (but unlikely since it would seriously screw up the parser) and your C++ compiler doesn't.

The correct form for using the pre-processor to block out code is:

#if 0
: : :
#endif

or

#ifdef NO_CHANCE_THAT_THIS_SYMBOL_WILL_EVER_EXIST
: : :
#endif
paxdiablo
I have some code that I compile occasionally that is compiled with -DNEVER_USED. I haven't investigated why - I hate to guess.
Jonathan Leffler
@Pax: actually, it is very unlikely that the C compiler allows the notation - it would be erroneous if it did. See also my comment to the question. I suggest removing your sentence "It's likely that...".
Jonathan Leffler
Not all C compilers are ANSI-compliant. I've used plenty of embedded compilers that allow all sorts of trickiness like that. But I'll fix it.
paxdiablo