| Deutsch English Français Italiano |
|
<87bju2htxy.fsf@nosuchdomain.example.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!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: Sat, 15 Mar 2025 14:20:41 -0700
Organization: None to speak of
Lines: 55
Message-ID: <87bju2htxy.fsf@nosuchdomain.example.com>
References: <vr4lgu$63fu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 15 Mar 2025 22:20:44 +0100 (CET)
Injection-Info: dont-email.me; posting-host="65766d3f94e315a3ff32ef79be62617b";
logging-data="315024"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Ye25LZ5vWMBNUelnxqAac"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:Gyui/PQVvuViYCPB4MJHo9ICDdo=
sha1:W5wKbDJYML3Nkuy0nCixG1Q0rTI=
Bytes: 2893
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.
> 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) {}
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
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */