For Programmers: Free Programming Magazines  


Home > Archive > C > February 2006 > stdint.h and portability









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author stdint.h and portability
copx

2006-02-28, 6:55 pm

I wonder how portable the exact width types defined by stdint.h are. I guess
target platforms are not required to actually have all those types, right?
What happens in that case?


Vladimir S. Oka

2006-02-28, 6:55 pm


copx wrote:
> I wonder how portable the exact width types defined by stdint.h are. I guess
> target platforms are not required to actually have all those types, right?
> What happens in that case?


There are certain types in stdint.h that are required, and every
implementation has to provide them. The rest is left for the particular
implementation, and you obviously can't guarentee portability of those.
Have a look in the standard for a list of required types.

Richard Bos

2006-02-28, 6:55 pm

"copx" <invalid@invalid.com> wrote:

> I wonder how portable the exact width types defined by stdint.h are. I guess
> target platforms are not required to actually have all those types, right?


Right. Except that if an implementation provides an (unsigned) integer
type of 8, 16, 32 or 64 bits, no matter what it is or how it is named,
it must also provide the corresponding (u)intN_t typedef in <stdint.h>.
If it does not otherwise provide a particular size integer, it needn't
define the typedef, and typedefs of any other size are completely
optional.

> What happens in that case?


They aren't there, and you can use #ifdef INT64_MIN (for example) to
test this. If the implementation provides these optional exact-width
typedefs, it must also #define these macros in <stdint.h>; if it does
not provide a typedef, it must not #define the corresponding macro.

Or you could use (u)int_leastN_t or (u)int_fastN_t, which are required
to exist for N equals 8, 16, 32 and 64, regardless of which other types
exist.

Richard
copx

2006-02-28, 6:55 pm


"Richard Bos" <rlb@hoekstra-uitgeverij.nl> schrieb im Newsbeitrag
news:44046296.359587293@news.xs4all.nl...
> "copx" <invalid@invalid.com> wrote:
>
>
> Right. Except that if an implementation provides an (unsigned) integer
> type of 8, 16, 32 or 64 bits, no matter what it is or how it is named,
> it must also provide the corresponding (u)intN_t typedef in <stdint.h>.
> If it does not otherwise provide a particular size integer, it needn't
> define the typedef, and typedefs of any other size are completely
> optional.
>
>
> They aren't there, and you can use #ifdef INT64_MIN (for example) to
> test this. If the implementation provides these optional exact-width
> typedefs, it must also #define these macros in <stdint.h>; if it does
> not provide a typedef, it must not #define the corresponding macro.
>
> Or you could use (u)int_leastN_t or (u)int_fastN_t, which are required
> to exist for N equals 8, 16, 32 and 64, regardless of which other types
> exist.


A very informative reply, thanks!




Keith Thompson

2006-02-28, 6:56 pm

rlb@hoekstra-uitgeverij.nl (Richard Bos) writes:
> "copx" <invalid@invalid.com> wrote:
>
> Right. Except that if an implementation provides an (unsigned) integer
> type of 8, 16, 32 or 64 bits, no matter what it is or how it is named,
> it must also provide the corresponding (u)intN_t typedef in <stdint.h>.
> If it does not otherwise provide a particular size integer, it needn't
> define the typedef, and typedefs of any other size are completely
> optional.


The {,u}int_{8,16,32,64}_t types are required only if the
implementation provides types of the specified sizes with no padding
bits (and for the signed types, with a two's complement
representation). If an implementation has a 32-bit signed integer
type with no padding bits, but its representation is one's-complement,
int32_t won't be defined (unless there's *also* a two's-complement
type).

The {,u}int_least{8,16,32,64}_t types and the
{,u}int_fast{8,16,32,64}_t type are required.

Types with sizes other than 8, 16, 32, and 64 are optional (and likely
to be rare).

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com