| Deutsch English Français Italiano |
|
<8734fcwwhf.fsf@nosuchdomain.example.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: __func__ is not a keyword
Date: Sun, 16 Mar 2025 13:29:00 -0700
Organization: None to speak of
Lines: 66
Message-ID: <8734fcwwhf.fsf@nosuchdomain.example.com>
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>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Sun, 16 Mar 2025 21:29:04 +0100 (CET)
Injection-Info: dont-email.me; posting-host="780a281062e134e978cc3552b9df7fb5";
logging-data="2639315"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193BS/FdH1I/ckFx+7HKJCy"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:KA/QL4A6KFvKpENLO60gLwDCwBk=
sha1:AiGr51b9SXIxjRqfLaxf9xCyoLI=
Bytes: 3938
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 */