DR 4## Prev <— Open —> Next DR 4##, or summary at top
Submitter: Douglas Walls
Submission Date: 2016-02-23
Source:WG14
Reference Document: N/A
Subject: Concern with keywords that match reserved identifiers
Summary
Should a conforming program be allowed to use identifiers spelled with a leading underscore followed by an uppercase letter that match the spelling of a keyword?The C committee has been adding keywords to the C standard spelled with a leading underscore followed by an uppercase letter so that they will not conflict with identifiers that are not already reserved to the implementation, i.e. so existing programs that conform to the C standard are not impacted by addition of new keywords in a new revision of the C standard.
So the C standard spells keywords in two ways:
As specified in 7.1.3, identifiers spelled with a leading underscore followed by an uppercase letter are reserved to the implementation. While those identifiers beginning with a lowercase letter are not. Thus, for example, a conforming program can use inline
as a macro name, but a conforming program cannot use _Noreturn
as a macro name.
Though the C committee has added new keywords from the reserved identifier namespace, the committee has not updated the rules about reserved identifiers. What I don't know is if that is intentional or an oversight, as I don't ever remember discussing the issue from that perspective during a committee meeting.
The issue came to my attention when I found some C standard headers defining _Noreturn
as a macro because they knew it is an identifier reserved to the implementation. I was a bit surprised, as it required a otherwise conforming program to #undef _Noreturn
in order to use the _Noreturn
keyword as a function specifier. The macro in this case was expanding to a gcc like attribute syntax recognized by the compiler.
Suggested Technical Corrigendum
Replace the first two bullets under 7.1.3p1 with:
— All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use, except those identifiers which are lexically identical to keywords. footnote)
— All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces, except those identifiers which are lexically identical to keywords.
footnote) Allows identifiers spelled with a leading underscore followed by an uppercase letter that match the spelling of a keyword to be used as macro names.
DR 4## Prev <— Open —> Next DR 4##, or summary at top
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4