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



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 .



Relevant Pages

  • Re: Book about Platform Builder
    ... possibility I see of anyone writing one is for 'resume building and name ... > into platform builder including a lot of changes about directory ... > So when will there be a new book about Platform Builder??? ... > 'Developing Windows CE.net Devices' will be published some lovely day) ...
    (microsoft.public.windowsce.platbuilder)
  • Re: embedded PC
    ... platform should ... Certainly when you use on-chip peripherals you ... Leaving the low level drivers aside, you can of course achieve some of ... flexibility be writing your application program in a way that is not ...
    (comp.arch.embedded)
  • 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. ... 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. ... Where you need at least 8 bits, but do not actually care how many bits, you could use uint_least8_t which will be 8 bits on systems that support it, but larger where not supported. ... You should also understand that stdint.h was added by the C99 standard which is not supported by most compilers. ...
    (comp.lang.c)
  • Re: reading multiple files
    ... The question is reasonable and, in my opinion, topical. ... writing a C program would meet the OP's needs better. ... why have a "similar" solution for each platform when you ... But by the time you've learned Perl and written a Perl interpreter for, ...
    (comp.lang.c)
  • Re: Economy of Expression
    ... find helps you to get the job done while also helping you to write less ... I'm interested in what helps you get more done while writing less code. ... Divide the program into four sections. ... Section two is "this program only, any platform", section three is "many programs, this platform only", and section four is "many programs, any platform". ...
    (comp.programming)