Re: stdint.h and portability



"copx" <invalid@xxxxxxxxxxx> 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
.



Relevant Pages

  • Re: Is there a convention mandating macros to be all-uppper-case?
    ... typedef std::wstring tstring; ... to keep namespaces intact. ... Macros are even worse, because they make the substitution completely blindly, without any consideration to their real meaning. ... At least with typedef, you can be sure it's not going to disrupt types in other namespaces, member functions in other classes, etc. ...
    (microsoft.public.vc.language)
  • Re: Why we should (not?) have closures after all
    ... A typedef facility will allow programmers to use ... expressiveness, further decreasing maintenance costs. ... C macros are particularly limited, but a real macro facility is ... how to prevent programmers from doing bad things. ...
    (comp.lang.java.programmer)
  • Re: Use a suffix or a type cast?
    ... I have heard that a suffix is not a good solution and type casts are ... We already had a typedef: ... But much easier than faffing with macros to try and achieve that was: ...
    (comp.lang.c)
  • Re: Operational and functional differences - #define vs typedef ?
    ... Most syntax checking and parsing occurs *after* macros are ... A typedef creates an alias for a type. ... type declarations is such that a macro isn't always going to work. ...
    (comp.lang.c)
  • Re: stdint.h and portability
    ... target platforms are not required to actually have all those types, ... it must also provide the corresponding intN_t typedef in. ... If the implementation provides these optional exact-width ... it must also #define these macros in; ...
    (comp.lang.c)