Re: Extent of the "as-if" rule

From: pete (pfiland_at_mindspring.com)
Date: 01/30/04


Date: Fri, 30 Jan 2004 17:36:18 GMT

Douglas A. Gwyn wrote:
>
> Dan Pop wrote:
> > Nope: such programs invoke undefined behaviour,
> > so they cannot be used in testing the conformance.
> > Even if this weren't the case, the action
> > in question could be performed 1e6 years after
> > the program startup...
>
> Your "logic" leads to the conclusion that conformance
> testing is impossible. Fortunately, you are wrong.

I believe that the claim, "Excedes ANSI Specifications",
is already in use. I always interpreted it to mean that the
compiler did not self destruct after translating one program.

And now if I may change change the topic to some old business:

Is it legitimate for a function like puts,
to return at the first sign of EOF, like this:

int puts(const char *s)
{
    while (*s != '\0') {
        if (putchar(*s) == EOF) {
            return EOF;
        }
        ++s;
    }
    return putchar('\n');
}

or must it keep hammering away, regardless of EOF, like this:

int puts(const char *s)
{
    int eof = 0;

    while (*s != '\0') {
        if (putchar(*s) == EOF) {
            eof = 1;
        }
        ++s;
    }
    return putchar('\n') == EOF || eof != 0 ? EOF : 1;
}

?

-- 
pete


Relevant Pages

  • Re: scanf behaviour
    ... char, i have to reread the input until I get the needed pos. ... user input a number that's too large to be stored in an integer. ... static int ignoreblks ... which may be \n or EOF ...
    (comp.lang.c)
  • Re: memory leak?
    ... char, short, int are all 16 bits. ... them rely on EOF being returned by the function. ... value distinct from all unsigned char values. ...
    (microsoft.public.vc.mfc)
  • Re: Is there any GENRIC MACROS in c for INTEGERS,CHARACTERS ?
    ... >> The descriptions of the ctype functions all take int values. ... >> that char is converted to int in this case and that if char is signed ... What is EOF for in this context? ... the 'space' characters and so 0 must be the result. ...
    (comp.lang.c)
  • Re: huffman encoder
    ... > to the specified stream and advances the position indicator for the ... > the error indicator for the stream is set and EOF is returned. ... the whole damn int does not go to the file, only the byte value of the int. ... flushing the, eg, so the last char is not truncated. ...
    (comp.compression)
  • Re: huffman encoder
    ... > to the specified stream and advances the position indicator for the ... > the error indicator for the stream is set and EOF is returned. ... the whole damn int does not go to the file, only the byte value of the int. ... flushing the, eg, so the last char is not truncated. ...
    (comp.compression)