Reputation: 162
From my understanding C99 new types such as uint32_t
, uint_fast64_t
, uintmax_t
etc. are defined in <stdint.h>
. However, I noticed they're also defined in stdlib.h
, and from gnu.org I found out that it is one of many headers checked, but in other websites only <stdint.h>
is referenced.
If I use these types including only <stdlib.h>
, which has them defined in my implementation, will my program be portable for other platforms or it could not work because in another computer they're only defined in <stdint.h>
?
My guess is that if I compile the program for every architecture/OS from my computer there won't be any problems, but the compilation could fail from another one because in that particular implementation the new types are only defined in another header.
Upvotes: 3
Views: 1013
Reputation: 141000
Is it necessary to include <stdint.h> to guarantee portability of C99 new types?
Yes, or <inttypes.h>
. Not really to "guarantee portability", but rather include <stdint.h>
to use those types at all in any compiler at any time. Note that uint32_t
and all intN_t
types are optional - they may (potentially...) not be available even after including stdint.h
.
If I use these types including only <stdlib.h>, which has them defined in my implementation, will my program be portable for other platforms or it could not work because in another computer they're only defined in <stdint.h>?
It could not work.
could fail from another one because in that particular implementation the new types are only defined in another header.
Yes.
from gnu.org I found out that it is one of many headers checked
The site you referenced is about build system configuration used to build GCC compiler itself, it's not related to what GCC is offering when compiling programs. GCC compiles only for twos complement platforms, you may be sure that stdint.h
will be available when you are using GCC.
Upvotes: 3