Re: Is there a standard way to write an 8 bit byte?
- From: Kristian Nybo <kristian@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 03 May 2005 00:37:29 +0300
Walter Roberson 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)
I'm actually using PNG.
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.
That's exactly what I'm worried about.
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.
Am I correct in deducing that if the file system stores files as byte streams, it doesn't matter how many bits wide char is as long as one doesn't try to write bytes with values that don't fit in an 8-bit byte?
Could there, as far as the standard is concerned, be a platform that uses 9-bit chars and stores files as bitstreams? :)
Kristian .
- References:
- Is there a standard way to write an 8 bit byte?
- From: Kristian Nybo
- Re: Is there a standard way to write an 8 bit byte?
- From: Walter Roberson
- Is there a standard way to write an 8 bit byte?
- Prev by Date: Re: memset
- Next by Date: Re: Is there a standard way to write an 8 bit byte?
- Previous by thread: Re: Is there a standard way to write an 8 bit byte?
- Next by thread: Re: Is there a standard way to write an 8 bit byte?
- Index(es):
Relevant Pages
|