Seebs <usenet-> writes:
> On 2011-05-18, rouben@shady.(none) (Rouben Rostamian) <rouben@shady> wrote:
>> #include <stdio.h>
>> int main(void)
>> {
>> printf("entering function %s\n", __func__);
>> return 0;
>> }
>>
>> Gcc compiles this program without a warning, even
>> in C89 mode, as in "gcc -Wall -pedantic -std=c89 progname.c".
>>
>> I expected to see a warning since the identifier __func__ was
>> introduced in C99. Is there a good reason why the compilation
>> does not fail in the C89 mode?
>
> Your code has undefined behavior. Why should you have any expectations
> about what it does?
Presumably because of the stipulations in 5.1.1.3, ie, at least a
diagnostic must be issued.
> __func__ is in the implementation's namespace. There is no lack of compliance
> with C89 if the implementation happens to define things in its own reserved
> namespace...
The problem is the Standard doesn't say that. The Standard talks
about 'reserved identifiers', not an 'implementation namespace'.
"Reserved" means a program may not declare or define them (modulo
section 7.1.7). The section that specifies which identifiers are
reserved (which is 7.1.3) says that they may be declared or
defined in _header files_ (clearly not relevant for __func__),
but AFAICS nothing otherwise. In the absence of any provision
allowing the implementation itself (as opposed to a header file)
to declare or define reserved identifiers, I don't see why we
should suppose that it's allowed to. And of course that would
mean that '__func__' would cause a syntax error, triggering a
diagnostic.
It's quite plausible that the original intention was to allow
implementations to define reserved identifiers however they like.
I just don't see any text in the Standard that grants such a
right.