Sujet : Re: __func__ is not a keyword
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 17. Mar 2025, 21:09:13
Autres entêtes
Organisation : None to speak of
Message-ID : <87y0x3v2qe.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7
User-Agent : Gnus/5.13 (Gnus v5.13)
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.comvoid Void(void) { Void(); } /* The recursive call of the void */