K
Kristian Nybo
Hi,
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.
At first it seemed that stdint.h and its uint8_t were the answer, but
then I noticed that uint8_t is only guaranteed to exist if the platform
has a data type that is exactly 8 bits wide, which put me back in square
one.
Is there a way around this, or will I just have to use uint8_t and
accept that my code might not work on every conceivable platform that
has an ANSI C compiler?
Kristian
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.
At first it seemed that stdint.h and its uint8_t were the answer, but
then I noticed that uint8_t is only guaranteed to exist if the platform
has a data type that is exactly 8 bits wide, which put me back in square
one.
Is there a way around this, or will I just have to use uint8_t and
accept that my code might not work on every conceivable platform that
has an ANSI C compiler?
Kristian