Tim said:
James said:
On 05/19/2011 05:03 AM, Sorc Chan wrote:
On 18 <<D0>> <<BC>> <<D0>> <<B0>> <<D0>> <<B9>> , 18:08, rouben@shady.(none) (Rouben Rostamian) wrote:
Consider:
#include <stdio.h>
int main(void)
{
printf("entering function %s\n", __func__);
return 0;
} [...]
What would _prevent_ GCC from providing this for C89 code?
Because __func__ in C98 undeclared such as any __ohhelloguys__ thing.
C89 imposes no such requirement. In fact, the main reason why the C89
standard said that a program using __func__ has undefined behavior is so
an implementation can choose to do anything it wishes to do with
__func__.
Except the C89 standard doesn't say that (nor does the C99
standard). Declaring or defining a reserved identifier
is undefined behavior, but just using one isn't.
In particular, the fact that the behavior is undefined gives
the compiler permission to treat __func__ as behaving in precisely the
fashion it's required to behave, according to the C99 standard.
No, under the C99 standard a diagnostic must be issued.
No diagnostic, no conformance.
Did you forget that __func__ is predefined in C99 (6.4.2.2)?
Or were you referring to declaring or defining __func__ yourself
(which does cause undefined behavior) as opposed to referring to it?
I think there may be some confusion here, due to a lack of precision in
my comment. I was saying that the undefined behavior gave a C90 compiler
permission to treat any use of __func__ the same way that a C99 compiler
would be mandated to treat it.
However, Tim is correct. It is the definition or declaration of a
reserved identifier which is explicitly stated to have undefined
behavior (at least, in C99, I'm not sure what C90 said).
It seems to me, however, that one of the key reasons for making those
identifiers reserved is to allow implementations the freedom to give
them specific meanings. If, as Sorc Chan has suggested above, the fact
that __func__ was a C90 reserved identifier meant that C90
implementations were prohibited from acting as though __func__ was a
declared identifier, then that prohibition would render the reserved
namespace almost completely useless to the implementation.
Might it be possible to argue that the C90 behavior of using __func__
was undefined "by the omission of any explicit definition
of behavior"? That's always a tricky rule to apply, and I'm not sure it
can be validly used here.