The variable __func__ in C89 in gcc

K

Kenny McCormack

Kiki Thompson said:
Hmm. Are you talking about references to __func__ outside a function
definition? (__func__ is implicitly defined immediately after the
opening "{" of any function definition.) Or are you saying that,
in general, a diagnostic is required for a reference to __foo__
if __foo__ is not predefined (for various values of foo)?

Remind me again: Just exactly how many angels fit on the head of a pin?

--
Windows 95 n. (Win-doze): A 32 bit extension to a 16 bit user interface for
an 8 bit operating system based on a 4 bit architecture from a 2 bit company
that can't stand 1 bit of competition.

Modern day upgrade --> Windows XP Professional x64: Windows is now a 64 bit
tweak of a 32 bit extension to a 16 bit user interface for an 8 bit
operating system based on a 4 bit architecture from a 2 bit company that
can't stand 1 bit of competition.
 
J

James Kuyper

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

Shao Miller

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.

It's a documented extension. The program that uses it is not strictly
conforming.
 
T

Tim Rentsch

Keith Thompson said:
Hmm. Are you talking about references to __func__ outside a function
definition? (__func__ is implicitly defined immediately after the
opening "{" of any function definition.) Or are you saying that,
in general, a diagnostic is required for a reference to __foo__
if __foo__ is not predefined (for various values of foo)?

I'm talking about references to any reserved identifier
when that identifier is not declared/defined, and what
an implementation obeying the C99 diagnostic rules
would have to do in such cases; best treat what I said
about __func__ as just a red herring and ignore it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Bug in gcc? 5
man gcc doesn't mention -std=c90 2
What a stupid gcc! 91
Bug in GCC? 10
long double in C89? 7
initialization of local static variable 41
gcc warning and 'basename' 19
Array based Binary Heap in C 19

Members online

No members online now.

Forum statistics

Threads
474,091
Messages
2,570,605
Members
47,225
Latest member
DarrinWhit

Latest Threads

Top