Re: Is there a standard way to write an 8 bit byte?
- From: Kristian Nybo <kristian@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 03 May 2005 01:09:15 +0300
Malcolm wrote:
"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.
Ah, I see. Although there may exist a platform where that code doesn't result in a file composed of eight bit bytes, all the other files native to such a platform would share this incompatibility with 8-bit machines, so the platform would either be completely isolated, in which case there's no problem, or it would have to have a way of converting its files into files that *are* composed of eight bit bytes. Great.
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: Malcolm
- Is there a standard way to write an 8 bit byte?
- Prev by Date: Re: unsigned wierdness
- Next by Date: Re: memset
- 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
|