Home >Backend Development >C++ >Is Redefining C Keywords with #define Standards Compliant?
Preprocessor Define and Keyword Redefinition in C
In the realm of C preprocessor directives, a heated debate has arisen regarding the standards compliance of redefining keywords using #define. Can a compliant preprocessor permit such practice?
The Preprocessor and Keywords
According to the C standard, §17.4.3.1.1/2 explicitly prohibits redefining a keyword within a translation unit that includes a standard library header. This restriction ensures the integrity of the standard library components.
C 0x and Keyword Redefinition
Initially, it was believed that C 0x (a now obsolete intermediate to C 11) would strengthen this prohibition to outright disallow keyword redefinition (§17.6.3.3.1). However, it has since been clarified that the rules in C 0x remain unchanged. The perceived revision arose from a text rearrangement that inadvertently misled some.
Standards Compliance and Keyword Redefinition
Given the current standards, a C program that redefines a keyword cannot be considered standards compliant. By violating the restriction against keyword redefinition, such a program breaches the integrity of the language and its built-in semantics.
The above is the detailed content of Is Redefining C Keywords with #define Standards Compliant?. For more information, please follow other related articles on the PHP Chinese website!