I have found some preprocessing directives in which macro name and replacement-list are same. For example, some preprocessing directives in stdbool.h provided by gcc.
#else /* __cplusplus */
/* Supporting <stdbool.h> in C++ is a GCC extension. */
#define _Bool bool
#define bool bool
#define false false
#define true true
#endif /* __cplusplus */
I don’t understand why the programmer wrote these preprocessing directives. They are useless, and the replacements will waste time. I know that this don’t cause infinite recursion. How to avoid infinite recursion? What’s the related provisions in C standard?
Infinite recursion during macro replacement is prevented by C++11 standard section 16.3.4 paragraph 2:
Basically, this means that a macro which appears inside its own expansion won’t be replaced again.
The reason that
true,bool, andfalseare defined as macros by the GCC extension is to make C++ code more compatible with C99. In C99, these are defined as macros in stdbool.h, so code may check if they are defined using e.g.#ifdef bool.