Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: macro names must be identifiers using #ifdef 0

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?

like image 510
Eduardo Avatar asked Jan 09 '09 01:01

Eduardo


People also ask

What is identifier in macro?

"Identifier" is roughly speaking a formal term for the syntax that specifies a name. Macros, functions, namespaces, types, variables all have names, and all those names are specified using identifiers.

What does Error macro mean?

The Macro Error message appears when there is an error in the macro that you were running. The specified method cannot be used on the specified object for one of the following reasons: An argument contains a value that is not valid.

What characters can be included in a macro name?

Macro names should only consist of alphanumeric characters and underscores, i.e. 'a-z' , 'A-Z' , '0-9' , and '_' , and the first character should not be a digit.

What is a macro name?

The macro name is what the user will use to call the macro into action. To define a macro name, the user must type Sub name() and press “enter” in the coding window of the editor. Pressing enter will automatically fill the window with the general format of an Excel macro.


1 Answers

The #ifdef directive is used to check if a preprocessor symbol is defined. The standard (C11 6.4.2 Identifiers) mandates that identifiers must not start with a digit:

identifier:     identifier-nondigit     identifier identifier-nondigit     identifier digit identifier-nondigit:     nondigit     universal-character-name     other implementation-defined characters> nondigit: one of     _ a b c d e f g h i j k l m     n o p q r s t u v w x y z     A B C D E F G H I J K L M     N O P Q R S T U V W X Y Z digit: one of     0 1 2 3 4 5 6 7 8 9 

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

#if 0 : : : #endif 

You can also use:

#ifdef NO_CHANCE_THAT_THIS_SYMBOL_WILL_EVER_EXIST : : : #endif 

but you need to be confident that the symbols will not be inadvertently set by code other than your own. In other words, don't use something like NOTUSED or DONOTCOMPILE which others may also use. To be safe, the #if option should be preferred.

like image 154
paxdiablo Avatar answered Sep 17 '22 16:09

paxdiablo