The difference between stdint.h and inttypes.h

What is the difference between stdint.h and inttypes.h?

If none of them is used, uint64_t is not recognized, but with any of them it is a specific type.

+53
c stdint uint64
Sep 29 '11 at 12:02
source share
2 answers

See the wikipedia article for inttypes.h.

Use stdint.h for a minimal set of definitions; use inttypes.h if you also need portable support for them in printf, scanf, etc.

+13
Sep 29 '11 at 12:06 on
source share

stdint.h

The inclusion of this file is a "minimum requirement" if you want to work with integer types with the specified width of C99 (ie, "int32_t", "uint16_t", etc.). If you include this file, you will receive definitions of these types so that you can use these types in variable and function declarations and perform operations on these data types.

inttypes.h

If you include this file, you will get everything that stdint.h provides (since inttypes.h includes stdint.h), but you will also get tools to do printf and scanf (and "fprintf", "fscanf", etc. ) with these types in a portable way. For example, you get the macro β€œPRIu16” so that you can print the integer uint16_t as follows:

#include <stdio.h> #include <inttypes.h> int main (int argc, char *argv[]) { // Only requires stdint.h to compile: uint16_t myvar = 65535; // Requires inttypes.h to compile: printf("myvar=%" PRIu16 "\n", myvar); } 
+109
Feb 06 '12 at 15:00
source share



All Articles