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?
"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.
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.
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.
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.
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.
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