Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #391281
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: __func__ is not a keyword |
| Date | 2025-03-16 13:29 -0700 |
| Organization | None to speak of |
| Message-ID | <8734fcwwhf.fsf@nosuchdomain.example.com> (permalink) |
| References | <vr4lgu$63fu$1@dont-email.me> <87bju2htxy.fsf@nosuchdomain.example.com> <6sCBP.1140938$t84d.713135@fx11.iad> <87bju0x10g.fsf@nosuchdomain.example.com> <20250316115725.530@kylheku.com> |
Kaz Kylheku <643-408-1753@kylheku.com> writes:
> On 2025-03-16, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>> source code and its behavior indicate that gcc treats __func__ as
>> a keyword, which is inconsistent with the info page. For example,
>> one would expect this:
>>
>> int main(void) {
>> {
>> int __func__;
>> }
>> }
>>
>> to be accepted, with the inner definition of __func__ hiding the
>> implicit static declaration, but gcc reports a syntax error.
>>
>> It's not a conformance issue, since __func__ is a reserved identifier
>> and any code that can tell whether it's a keyword has undefined
>> behavior.
>
> But __func__ is not a reserved identifier! Inside a function, it's a
> documented identifier with specified properties, and those properties do
> not support an interpretation that it may be a keyword.
"All identifiers that begin with a double underscore (__) or begin with
an underscore (_) followed by an uppercase letter are reserved for any
use, except those identifiers which are lexically identical to
keywords."
My interpretation is that the fact that the language defines a meaning
for __func__ doesn't exclude it from the set of reserved identifiers.
> We have to distinguish between specific, defined, standard identifiers
> allocated from a reserved namespace, and the reserved namespace itself.
>
> If gcc (in c99 mode or later) *allowed* int _Bool = 42; would you
> call that conforming, because _B* is in the reserved namespace, so
> any behavior is okay?
No, that's a syntax error because _Bool is a keyword, and keywords
are not identifiers. "When preprocessing tokens are converted to
tokens during translation phase 7, if a preprocessing token could be
converted to either a keyword or an identifier, it is converted to
a keyword except in an attribute token." Keywords and identifiers
are disjoint sets.
> Since __func__ is not described as existing outside of a function,
> there, it is just an identifier landing in the reserved namespace.
As far as the language is concerned yes, but gcc doesn't treat it
that way.
Are you suggesting that a conforming compiler must accept the above
code (defining __func__ in an inner scope)? If so, I disagree.
gcc treating __func__ as a keyword arguably violates the intent of
the standard, but not in a way that affects conformance (unless I'm
missing something). It behaves *as if* __func__ were an identifier
in the reserved space, with some instances of undefined behavior
behaving in odd but conforming ways.
(Practically, not being able to define my own entity named __func__
is no great loss.)
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
__func__ is not a keyword Thiago Adams <thiago.adams@gmail.com> - 2025-03-15 16:47 -0300
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-15 14:20 -0700
Re: __func__ is not a keyword Thiago Adams <thiago.adams@gmail.com> - 2025-03-15 18:30 -0300
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-15 14:53 -0700
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-15 15:04 -0700
Re: __func__ is not a keyword Kaz Kylheku <643-408-1753@kylheku.com> - 2025-03-16 07:18 +0000
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-16 02:06 -0700
Re: __func__ is not a keyword Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-03-18 10:00 -0700
Re: __func__ is not a keyword scott@slp53.sl.home (Scott Lurndal) - 2025-03-16 15:51 +0000
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-16 11:51 -0700
Re: __func__ is not a keyword Kaz Kylheku <643-408-1753@kylheku.com> - 2025-03-16 19:05 +0000
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-16 13:29 -0700
Re: __func__ is not a keyword Kaz Kylheku <643-408-1753@kylheku.com> - 2025-03-17 17:03 +0000
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-17 13:09 -0700
Re: __func__ is not a keyword Kaz Kylheku <643-408-1753@kylheku.com> - 2025-03-17 20:31 +0000
Re: __func__ is not a keyword James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-03-16 16:35 -0400
Re: __func__ is not a keyword Mario Rosell <usenet@mariorosell.es> - 2026-04-17 20:19 +0000
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-17 14:15 -0700
csiph-web