Allowed to undef EOF?

Discussion in 'C Programming' started by Old Wolf, Apr 5, 2007.

  1. Old Wolf

    Old Wolf Guest

    Is this program alright?

    #include <stdio.h>
    #undef EOF

    int EOF(void) { return 0; }
    int main(void) { return EOF(); }
    Old Wolf, Apr 5, 2007
    #1
    1. Advertising

  2. "Old Wolf" <> writes:
    > 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.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Apr 5, 2007
    #2
    1. Advertising

  3. Old Wolf

    Eric Sosman Guest

    Keith Thompson wrote On 04/04/07 20:09,:
    > "Old Wolf" <> writes:
    >
    >>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.


    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.

    --
    Eric Sosman, Apr 5, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kobu
    Replies:
    10
    Views:
    605
    Keith Thompson
    Mar 4, 2005
  2. SpreadTooThin

    ifstream eof not reporting eof?

    SpreadTooThin, Jun 13, 2007, in forum: C++
    Replies:
    10
    Views:
    677
    James Kanze
    Jun 15, 2007
  3. Iñaki Baz Castillo
    Replies:
    13
    Views:
    477
    Iñaki Baz Castillo
    May 1, 2011
  4. Jan Burse
    Replies:
    67
    Views:
    1,029
    Jan Burse
    Mar 14, 2012
  5. Tim McDaniel

    undef($foo) versus $foo = undef()?

    Tim McDaniel, Aug 19, 2009, in forum: Perl Misc
    Replies:
    6
    Views:
    135
    Peter J. Holzer
    Aug 19, 2009
Loading...

Share This Page