Re: Is there a standard way to write an 8 bit byte?




"Kristian Nybo" <kristian@xxxxxxxxxxxxxxxxxx> wrote
> I'm writing a simple image file exporter as part of a school project, and
> I would like to write completely platform-independent code if at all
> possible. The problem I've run into is that apparently there's no
> guarantee that a particular implementation will have a data type that is
> exactly 8 bits wide; char is only guaranteed to be at least 8 bits.
> Correct me if I'm wrong, but I assume that if CHAR_BIT happens to be, say,
> 9, writing a char into a file in binary mode would result in 9 bits being
> written.
>
Just use fgetc and fputc to write integers between 0 and 255.

There is no cast iron guarantee in the C standard that this will produce the
file you want, if say chars are 9 bits wide. However in practise there will
always be an easy way to convert such files so that they can be read by
8-bit machines (maybe by running them though a converter program)..
Computers exist in the real world and have to communicate with each other.


.



Relevant Pages

  • Re: Is there a standard way to write an 8 bit byte?
    ... and I would like to write completely platform-independent code if at all possible. ... guarantee that a particular implementation will have a data type that is exactly 8 bits wide; char is only guaranteed to be at least 8 bits. ... Correct me if I'm wrong, but I assume that if CHAR_BIT happens to be, say, 9, writing a char into a file in binary mode would result in 9 bits being written. ... they are byte or word streams. ...
    (comp.lang.c)
  • Re: Is there a standard way to write an 8 bit byte?
    ... >guarantee that a particular implementation will have a data type that is ... char is only guaranteed to be at least 8 bits. ... >say, 9, writing a char into a file in binary mode would result in 9 bits ... as bitstreams: they are byte or word streams. ...
    (comp.lang.c)
  • Re: Swap file on USB
    ... flash-internal blocks are larger than the ... and erasing is at block granularity, ... while writing happens at word granularity. ... guarantee that the designers of a particular flash controller take ...
    (comp.os.linux.hardware)
  • Re: fwrite() misses writing a byte
    ... binary files which is just some marshalled data. ... I presume that Datais a single byte (type char, signed char, or ... then you're just writing the first byte ... meaningful error message. ...
    (comp.lang.c)
  • Re: Access violation in free()
    ... Better: char *CopyString ... writing. ... looking for a new word processor. ...
    (comp.lang.c)