Re: __func__ is not a keyword

Liste des GroupesRevenir à cl c 
Sujet : Re: __func__ is not a keyword
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.c
Date : 16. Mar 2025, 21:29:00
Autres entêtes
Organisation : None to speak of
Message-ID : <8734fcwwhf.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5
User-Agent : Gnus/5.13 (Gnus v5.13)
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 */

Date Sujet#  Auteur
15 Mar 25 * __func__ is not a keyword15Thiago Adams
15 Mar 25 `* Re: __func__ is not a keyword14Keith Thompson
15 Mar 25  +* Re: __func__ is not a keyword3Thiago Adams
15 Mar 25  i`* Re: __func__ is not a keyword2Keith Thompson
15 Mar 25  i `- Re: __func__ is not a keyword1Keith Thompson
16 Mar 25  +* Re: __func__ is not a keyword3Kaz Kylheku
16 Mar 25  i`* Re: __func__ is not a keyword2Keith Thompson
18 Mar 25  i `- Re: __func__ is not a keyword1Tim Rentsch
16 Mar 25  `* Re: __func__ is not a keyword7Keith Thompson
16 Mar 25   `* Re: __func__ is not a keyword6Kaz Kylheku
16 Mar 25    +* Re: __func__ is not a keyword4Keith Thompson
17 Mar 25    i`* Re: __func__ is not a keyword3Kaz Kylheku
17 Mar 25    i `* Re: __func__ is not a keyword2Keith Thompson
17 Mar 25    i  `- Re: __func__ is not a keyword1Kaz Kylheku
16 Mar 25    `- Re: __func__ is not a keyword1James Kuyper

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal