Allowed to undef EOF?

O

Old Wolf

Is this program alright?

#include <stdio.h>
#undef EOF

int EOF(void) { return 0; }
int main(void) { return EOF(); }
 
K

Keith Thompson

Old Wolf said:
Is this program alright?

#include <stdio.h>
#undef EOF

int EOF(void) { return 0; }
int main(void) { return EOF(); }

Certainly not. It hurts my brain. Hurting my brain is not all right.

But to answer the question you *meant* to ask, I don't think C99 7.1.3
"Reserved identifiers" either forbid this or makes it undefined
behavior.

It does say:

Each macro name in any of the following subclauses (including the
future library directions) is reserved for use as specified if any
of its associated headers is included; unless explicitly stated
otherwise (see 7.1.4).

The "explicitly stated otherwise" clause doesn't apply to EOF.
I'm not 100% sure what "reserved for use as specified" means.
 
E

Eric Sosman

Keith Thompson wrote On 04/04/07 20:09,:
Certainly not. It hurts my brain. Hurting my brain is not all right.

But to answer the question you *meant* to ask, I don't think C99 7.1.3
"Reserved identifiers" either forbid this or makes it undefined
behavior.

It does say:

Each macro name in any of the following subclauses (including the
future library directions) is reserved for use as specified if any
of its associated headers is included; unless explicitly stated
otherwise (see 7.1.4).

The "explicitly stated otherwise" clause doesn't apply to EOF.
I'm not 100% sure what "reserved for use as specified" means.

I think it means "the program is not all right."
It includes <stdio.h>, which defines the macro EOF, so
EOF cannot be used as an identifier for anything else.
No, not even if #undef'ed; the compiler is allowed to
behave "magically" w.r.t. reserved identifiers.

It is permissible to #undef a "masking macro" to
ensure making a call to an actual library function (7.1.4/1).
However, EOF is not such a macro, so I don't think #undef'ing
it is permitted.

... and it makes my brain hurt too, Mister Gumby.
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top