Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #391291

Re: __func__ is not a keyword

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 Mon, 17 Mar 2025 13:09:13 -0700
Organization None to speak of
Lines 52
Message-ID <87y0x3v2qe.fsf@nosuchdomain.example.com> (permalink)
References <vr4lgu$63fu$1@dont-email.me> <87bju2htxy.fsf@nosuchdomain.example.com> <6sCBP.1140938$t84d.713135@fx11.iad> <87bju0x10g.fsf@nosuchdomain.example.com> <20250316115725.530@kylheku.com> <8734fcwwhf.fsf@nosuchdomain.example.com> <20250317095147.230@kylheku.com>
MIME-Version 1.0
Content-Type text/plain
Injection-Date Mon, 17 Mar 2025 21:09:14 +0100 (CET)
Injection-Info dont-email.me; posting-host="65462c6a1248bdf7df5d9433427808eb"; logging-data="880281"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gzU/VE6izpXBLUTPt5YHq"
User-Agent Gnus/5.13 (Gnus v5.13)
Cancel-Lock sha1:fmx4BfC1hN6hEOZDUYxi0pvPXQs= sha1:7tPZPC1tVIxUtt86svTYYR2Gt2U=
Xref csiph.com comp.lang.c:391291

Show key headers only | View raw


Kaz Kylheku <643-408-1753@kylheku.com> writes:
> On 2025-03-16, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>> Are you suggesting that a conforming compiler must accept the above
>> code (defining __func__ in an inner scope)?  If so, I disagree.
>
> I was initially divided on this one.
>
> On the one hand, inside a function, __func__ is not reserved (for future
> use); it is described as being bound as a variable name, and that makes
> it compatible with lexical shadowing.

That's where I disagree, though I'm not 100% certain.

Identifiers starting with __ are not conditionally reserved, and
they're not reserved "for future use".  They're simply "reserved
for any use".

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

The fact that the language defines its own use for __func__ IMHO
doesn't unreserve it.  Referring to __func__ within a function
definition is of course allowed, but declaring or defining it still
has undefined behavior.

I'm using the N3096 draft at the moment; other drafts should have
similar or identical wording.  6.4.2.1 discusses identifiers,
and says that certain identifiers are "reserved for any use".
6.4.2.2 discusses predefined identifiers, specifically __func__
(which is the only predefined identifier).  I think you're assuming
that 6.4.2.2 describes an exception to the rules in 6.4.2.1.  I think
it doesn't; __func__ is specified in a way that's consistent with
it continuing to be reserved for any use.

And James Kuyper has pointed out the footnote in 6.4.2.2:

    Since the name __func__ is reserved for any use by the
    implementation (7.1.3), if any other identifier is explicitly
    declared using the name __func__, the behavior is undefined.

[...]

> Of course, from a portable programming point of view, we must regard
> __func__ as off-limits. In light of the above possibilities, though, it
> seems that it would be best to formally interpret it that way, too.

Agreed.

-- 
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 | NextPrevious in thread | Next in thread | Find similar


Thread

__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