I'm curious as to what can be used as an identifier for the #define directive in C and/or C++. Is every string token legal?
For example, would the following code compile?
#define EMPTY ;;
for(EMPTY){
function();
}
I'm curious as to what can be used as an identifier for the #define directive in C and/or C++. Is every string token legal?
For example, would the following code compile?
#define EMPTY ;;
for(EMPTY){
function();
}
The rules are more or less the same as for other identifiers. Some names (e.g., those with a leading underscore followed by another underscore or a capital letter) are reserved for the implementation. In C++, names with two successive underscores (anywhere, not just the beginning) are reserved as well.
There is one other proviso that's specific to #define
's in C++ (but not C): you're not allowed to re-define a reserved word. So a name like EMPTY
is fine, but a name like for
or auto
would not be.
The syntactic rules for regular identifiers such as names of variables, functions, goto labels, etc... are the same for identifiers used with preprocessor directives.
The C standard has a precise and unique definition for the word identifier, so wherever the word identifier appears in the standard, it is that same thing.