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



In article <ZWvde.166$Rl4.127@xxxxxxxxxxxxxxxxxxxxxxx>,
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.

PBM -- Portable BitMap (monochrome)
PNG -- Portable Network Graphics (colour, lossless compression)

>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.

Yes -- but what happens when you take that file to an 8-bit machine
is undefined. Very few filesystems (none I -know- of) store files
as bitstreams: they are byte or word streams. Ethernet is bitstream,
but most well-known file-transfer protocols involve 8-bit characters.
--
Ceci, ce n'est pas une idée.
.



Relevant Pages

  • Re: Is there a standard way to write an 8 bit byte?
    ... > I would like to write completely platform-independent code if at all ... char is only guaranteed to be at least 8 bits. ... writing a char into a file in binary mode would result in 9 bits being ... There is no cast iron guarantee in the C standard that this will produce the ...
    (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)
  • Re: Newbie question: accessing global variable on multiprocessor
    ... system is still different from a single-processor ... some value at a memory address, and once thread A has finished writing ... may be other reasons why this wouldn't be guaranteed even on a single- ... and it seems like the only guarantee you get is ...
    (comp.programming.threads)