Re: problem with binary file

From: Floyd L. Davidson (floyd_at_apaflo.com)
Date: 08/13/05


Date: Sat, 13 Aug 2005 12:56:13 -0800


"Peter T. Breuer" <ptb@oboe.it.uc3m.es> wrote:
>Reinardt Behm <reinhardt.behm@t-online.de> wrote:
>> > EOF is -1 which is just a character like any other (255 usually). You
>> > should read untl EOF is _signalled_ from your reader method, not until
>> > it is _read_.
>>
>> This is nonsense. EOF is not a _char_ it is an _int_
>
>Nonsense. Chars are (very short ints). Even shorter than shorts.

Nonsense! EOF is *not* a "just a character", is not data, and
is never 255.

It is a flag returned by the read(2) function, indicating that
an attempt has been made to read past the end of the file.

>> (value 0xffff if int is
>> 16 bit) and you should always read ints from a file to be able to detect
>> EOF.

EOF is not a 16 bit int either. It is a *flag*, and on 32 bit
systems is 32 bits wide, on 64 bit systems is 64 bits wide,
etc. etc.

>You don't seem to understand. EOF will be SIGNALLED, not read. The
>reason why his placing a -1 (char) in the file does not stop the method
>reading beyond the CHAR is because it is a byte like any other.

That is correct. (Which begs the question of why you said it
was 255, usually?)

-- 
Floyd L. Davidson            <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)                         floyd@apaflo.com


Relevant Pages

  • Re: Natural size: int
    ... A char should be the smallest addressable unit of memory; ... You assume that shorter ints are somehow more efficient than longer ... many modern processors have slow shorts and int is no faster ... and chars may be faster than ...
    (comp.lang.c)
  • Re: liitle endian
    ... // little endian ... System has 16-bit chars, 16-bit shorts, 32-bit ints, and is ...
    (comp.lang.c)
  • Re: liitle endian
    ... // little endian ... System has 16-bit chars, 16-bit shorts, 32-bit ints, and is ...
    (comp.lang.c)
  • Re: Malcolms new book
    ... buffer (ints being too small) but *can* accept negative values. ... support for perfectly legitimate buffers. ... But that's not what he said; he said you can't pass chars to the ...
    (comp.lang.c)
  • Re: Thou shalt have no other gods before the ANSI C standard
    ... > Those customers who were careful enough to write their code portably ... the shorts to unsigned chars because the old compiler used 16 bit ints and 8 bit ...
    (sci.crypt)