Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #391278
| Path | csiph.com!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 11:51:11 -0700 |
| Organization | None to speak of |
| Lines | 47 |
| Message-ID | <87bju0x10g.fsf@nosuchdomain.example.com> (permalink) |
| References | <vr4lgu$63fu$1@dont-email.me> <87bju2htxy.fsf@nosuchdomain.example.com> <6sCBP.1140938$t84d.713135@fx11.iad> |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Date | Sun, 16 Mar 2025 19:51:15 +0100 (CET) |
| Injection-Info | dont-email.me; posting-host="780a281062e134e978cc3552b9df7fb5"; logging-data="2462235"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Eevuy2TpibkVtz0xQHlj/" |
| User-Agent | Gnus/5.13 (Gnus v5.13) |
| Cancel-Lock | sha1:yQHlULsVB2ygfvb6F8VO8e/OeFU= sha1:9COzNnUoa2lmtZMILJVTGOrws6Y= |
| Xref | csiph.com comp.lang.c:391278 |
Show key headers only | View raw
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 */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
__func__ is not a keyword Thiago Adams <thiago.adams@gmail.com> - 2025-03-15 16:47 -0300
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-15 14:20 -0700
Re: __func__ is not a keyword Thiago Adams <thiago.adams@gmail.com> - 2025-03-15 18:30 -0300
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-15 14:53 -0700
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-15 15:04 -0700
Re: __func__ is not a keyword Kaz Kylheku <643-408-1753@kylheku.com> - 2025-03-16 07:18 +0000
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-16 02:06 -0700
Re: __func__ is not a keyword Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-03-18 10:00 -0700
Re: __func__ is not a keyword scott@slp53.sl.home (Scott Lurndal) - 2025-03-16 15:51 +0000
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-16 11:51 -0700
Re: __func__ is not a keyword Kaz Kylheku <643-408-1753@kylheku.com> - 2025-03-16 19:05 +0000
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-16 13:29 -0700
Re: __func__ is not a keyword Kaz Kylheku <643-408-1753@kylheku.com> - 2025-03-17 17:03 +0000
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-03-17 13:09 -0700
Re: __func__ is not a keyword Kaz Kylheku <643-408-1753@kylheku.com> - 2025-03-17 20:31 +0000
Re: __func__ is not a keyword James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-03-16 16:35 -0400
Re: __func__ is not a keyword Mario Rosell <usenet@mariorosell.es> - 2026-04-17 20:19 +0000
Re: __func__ is not a keyword Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-17 14:15 -0700
csiph-web