Home >Backend Development >C++ >Is Redefining C Keywords with #define Standards Compliant?

Is Redefining C Keywords with #define Standards Compliant?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-21 04:03:17834browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn