Re: __func__ is not a keyword

Liste des GroupesRevenir à cl c 
Sujet : Re: __func__ is not a keyword
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.c
Date : 15. Mar 2025, 22:30:17
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vr4rh9$b38v$1@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
Em 3/15/2025 6:20 PM, Keith Thompson escreveu:
Thiago Adams <thiago.adams@gmail.com> writes:
This program does not compile..in gcc and clang
>
int __func__  i =1;
>
int main () {}
>
error: expected identifier...
 The "i" makes that a syntax error anyway, even if "__func__" were
accepted as an ordinary identifier.  Still, you have found something
odd.
 
Yes sorry...

Standard has..
>
"The identifier __func__ shall be implicitly declared by the
translator as if, immediately following
the opening brace of each function definition, the declaration" ...
>
>
My understand is that __func__   is not a keyword and that is
something defined inside the functions.. so I don’t know why gcc and
clang complains in the file scope.
 If I change your program to:
      int __func__ = 1;
     int main(void) {}
 
yes..now I don't known if I did it right at first time.
but the problem I was talking about still there. :)

both gcc and clang complain "error: expected identifier or ‘(’".
If I change it from __func__ to __foo__, neither gcc nor clang
complains.
      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.
     ...
     If the program declares or defines an identifier in a context in
     which it is reserved (other than as allowed by 7.1.4), the behavior
     is undefined.
 So the program has undefined behavior, which means that terminating
the translation with the issuance of a diagnostic message is
permitted.
 I'm mildly curious how gcc and clang treat "__func__" internally
that leads to this odd behavior.  The obvious way to implement it
would be to internally create a declaration of __func__ on entry
to each function definition, which shouldn't cause the symptom
you're seeing.  But it's not a conformance issue
 
I think __func__ is begin used as keyword inside gcc /clang.
Thanks for clarifying it.
I think this UB could be removed.

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