Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Thiago Adams Newsgroups: comp.lang.c Subject: Re: __func__ is not a keyword Date: Sat, 15 Mar 2025 18:30:17 -0300 Organization: A noiseless patient Spider Lines: 68 Message-ID: References: <87bju2htxy.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 15 Mar 2025 22:30:17 +0100 (CET) Injection-Info: dont-email.me; posting-host="7c3e0c65bee7f4dbeea0c670cee9b5e9"; logging-data="363807"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+nWw4Hj8eoaraofUEvQfAKlxWuBzRoouM=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:dkeH76zNIlTOvdcH9w7uxUcpR7c= In-Reply-To: <87bju2htxy.fsf@nosuchdomain.example.com> Content-Language: en-GB Bytes: 3273 Em 3/15/2025 6:20 PM, Keith Thompson escreveu: > Thiago Adams 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.