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, 19:51:11
Autres entêtes
Organisation : None to speak of
Message-ID : <87bju0x10g.fsf@nosuchdomain.example.com>
References : 1 2 3
User-Agent : Gnus/5.13 (Gnus v5.13)
scott@slp53.sl.home (Scott Lurndal) writes:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
Thiago Adams <thiago.adams@gmail.com> writes:
This program does not compile..in gcc and clang
>
int __func__  i =1;
>
I'm mildly curious how gcc and clang treat "__func__" internally
that leads to this odd behavior.
>
From the gcc info page:
>
   GCC provides three magic variables that hold the name of the current
   function, as a string.  The first of these is '__func__', which is part
   of the C99 standard:
>
    The identifier '__func__' is implicitly declared by the translator as
   if, immediately following the opening brace of each function definition,
   the declaration
>
     static const char __func__[] = "function-name";
>
   appeared, where function-name is the name of the lexically-enclosing
   function.  This name is the unadorned name of the function.

But that doesn't tell us how it's treated internally and it's
inconsistent with gcc's actual behavior.  Both a look at gcc's
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.

--
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