Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #9377

Re: Random thought -- EOF and errno

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Random thought -- EOF and errno
Date 2011-08-13 18:04 -0700
Organization None to speak of
Message-ID <lnmxfc4xdg.fsf@nuthaus.mib.org> (permalink)
References (4 earlier) <0.06274cbd79e04c20808d.20110813012700BST.87ei0qjgvf.fsf@bsb.me.uk> <lnpqka5cc1.fsf@nuthaus.mib.org> <0.83adf5802e654f78a515.20110813143800BST.87d3g9ig93.fsf@bsb.me.uk> <lnzkjd403q.fsf@nuthaus.mib.org> <j26rbp$p11$1@dont-email.me>

Show all headers | View raw


Eric Sosman <esosman@ieee-dot-org.invalid> writes:
> On 8/13/2011 2:50 PM, Keith Thompson wrote:
>> [...]
>> I think you're assuming that this program:
>>
>> #include<errno.h>
>> #include<stdio.h>
>> int main(void){}
>>
>> is strictly conforming.  Of course it *should* be, but I'm arguing that
>> the reservation of the identifier EOF by both<stdio.h>  and<errno.h>
>> creates an unintentional loophole, implying that it isn't.  It depends
>> on the implementation-defined choice of whether<errno.h>  defines EOF.
>
>      7.1.2p4: "[...] However, if an identifier is declared or defined
> in more than one header, the second and subsequent associated headers
> may be included after the initial reference to the identifier."
>
>      Assuming "initial reference" also covers the header's declaration
> or definition, then both <stdio.h> and <errno.h> can be #include'd in
> the same translation unit, and in either order.  Either must tolerate
> the possible declaration of EOF by the other.

Good catch!

So having "#define EOF 42" in <errno.h> would be non-conforming, since
it would cause the above program to fail.

Well, maybe.  I suppose if the compiler merely issues a warning for an
inconsistently redefined macro, then it would still compile the program.
Warnings on strictly conforming programs are permitted.  *Sigh*.

And the wording for <errno.h> is a bit vague.  EDOM, EILSEQ, and ERANGE
are required to be positive, but (C99 7.5p4):

    Additional macro definitions, beginning with E and a digit
    or E and an uppercase letter, may also be specified by the
    implementation.

It doesn't say that these additional macro definitions must be
positive, that they must expand to integer constant expressions, or
that they're error codes.  They could even be function-like macros.
Or both <errno.h> and <stdio.h> could have "#define EOF (-1)".

Implementer sanity, not the Standard, is what saves us from such bizarre
things.  The only common variant I know of is that different E* macros
might have the same value.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Random thought -- EOF and errno Kenneth Brody <kenbrody@spamcop.net> - 2011-08-12 12:04 -0400
  Re: Random thought -- EOF and errno James Kuyper <jameskuyper@verizon.net> - 2011-08-12 12:27 -0400
    Re: Random thought -- EOF and errno Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-13 00:12 +0100
      Re: Random thought -- EOF and errno Keith Thompson <kst-u@mib.org> - 2011-08-12 16:30 -0700
        Re: Random thought -- EOF and errno Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-13 01:27 +0100
          Re: Random thought -- EOF and errno Keith Thompson <kst-u@mib.org> - 2011-08-12 18:28 -0700
            Re: Random thought -- EOF and errno Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-13 14:38 +0100
              Re: Random thought -- EOF and errno Keith Thompson <kst-u@mib.org> - 2011-08-13 11:50 -0700
                Re: Random thought -- EOF and errno Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-13 17:45 -0400
                Re: Random thought -- EOF and errno Keith Thompson <kst-u@mib.org> - 2011-08-13 18:04 -0700
                Re: Random thought -- EOF and errno Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-13 22:53 +0100
                Re: Random thought -- EOF and errno Keith Thompson <kst-u@mib.org> - 2011-08-13 17:57 -0700
                Re: Random thought -- EOF and errno Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-13 21:06 -0400
                Re: Random thought -- EOF and errno Keith Thompson <kst-u@mib.org> - 2011-08-13 18:39 -0700
                Re: Random thought -- EOF and errno Tim Rentsch <txr@alumni.caltech.edu> - 2011-09-04 12:59 -0700
      Re: Random thought -- EOF and errno James Kuyper <jameskuyper@verizon.net> - 2011-08-12 20:51 -0400
        Re: Random thought -- EOF and errno Nobody <nobody@nowhere.com> - 2011-08-13 05:55 +0100
          Re: Random thought -- EOF and errno Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-13 14:49 +0100
        Re: Random thought -- EOF and errno Kenneth Brody <kenbrody@spamcop.net> - 2011-08-15 15:02 -0400
          Re: Random thought -- EOF and errno Keith Thompson <kst-u@mib.org> - 2011-08-15 12:18 -0700
          Re: Random thought -- EOF and errno James Kuyper <jameskuyper@verizon.net> - 2011-08-15 21:54 -0400
            Re: Random thought -- EOF and errno Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-16 04:21 +0100
        Re: Random thought -- EOF and errno William Ahern <william@wilbur.25thandClement.com> - 2011-08-15 12:56 -0700
  Re: Random thought -- EOF and errno Seebs <usenet-nospam@seebs.net> - 2011-08-12 18:37 +0000
  Re: Random thought -- EOF and errno Nobody <nobody@nowhere.com> - 2011-08-13 06:00 +0100
    Re: Random thought -- EOF and errno Kenneth Brody <kenbrody@spamcop.net> - 2011-08-15 15:05 -0400
      Re: Random thought -- EOF and errno Keith Thompson <kst-u@mib.org> - 2011-08-15 12:14 -0700
      Re: Random thought -- EOF and errno gordonb.gl0ml@burditt.org (Gordon Burditt) - 2011-08-16 04:31 -0500

csiph-web