Re: Specific sizes of variable types



Hey Keith,

Thanks a lot! I was just exploring my /usr/include and stumbled upon
stdint.h and saw all these typedefs. Exactly what I needed. One more
question. What happens if you user signed char or unsigned char for
input/output? Does it matter which one I'm using?

Regards


Keith Thompson wrote:
> "gamehack" <gamehack@xxxxxxxxx> writes:
> > I'm writing an application which will be opening binary files with
> > definite sizes for integers(2 byte integers and 4 byte longs). Is there
> > a portable way in being sure that each integer will be exactly 2 bytes?
> > Should I have a platform dependent header file which checks for
> > CHAR_BIT and sizeof(int) etc and have a few typedefs like int16, long32
> > etc.
> > <OT>
> > If I have to go non-portable, then what's the way to determine the
> > sizes before compilation and typedef accordingly?
> > </OT>
>
> C99 has a standard header called <stdint.h>, which provides typedefs
> for int8_t, uint8_t, int16_t, uint16_t, int32_t, etc. Those are
> exact-width types, and the signed ones are required to be
> 2's-complement with no padding bits; they may not exist if the
> implementation doesn't provide types with the required attributes. It
> also provides "least" types (the smallest type with at least the
> specified number of bits) and "fast" types (the "fastest" type with at
> least the specified number of bits); it's not always clear what
> "fastest" really means.
>
> If your implementation doesn't provide this header, you can roll your
> own, or you can use Doug Gwyn's C90-compatible public-domain
> implementation q8 at <http://www.lysator.liu.se/c/q8/>. You'll
> probably need to do some tailoring for your system.
>
> --
> Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
> San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
> We must do something. This is something. Therefore, we must do this.

.



Relevant Pages

  • Re: Specific sizes of variable types
    ... > definite sizes for integers(2 byte integers and 4 byte longs). ... C99 has a standard header called, which provides typedefs ...
    (comp.lang.c)
  • Re: Questions regarding cyclic header dependency
    ... Is there any tools that could report where cyclic header dependency ... "cyclic" include dependencies that do not work. ... Even if your compiler allows multiple identical typedefs, ... If you want to communicate that A_t is in truth struct A and every ...
    (comp.lang.c)
  • Re: dev_t / udev_t confusion ?
    ... No objection from me ... Avoid using typedefs for structure types. ... that defines the typedef must be included before the header that uses it, ...
    (freebsd-arch)
  • Re: dev_t / udev_t confusion ?
    ... No objection from me ... Avoid using typedefs for structure types. ... that defines the typedef must be included before the header that uses it, ...
    (freebsd-arch)
  • Re: Specific sizes of variable types
    ... > definite sizes for integers. ... > CHAR_BIT and sizeofetc and have a few typedefs like int16, ... you could be made redundant, ...
    (comp.lang.c)