NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
kstdint.h
Go to the documentation of this file.
1 #ifndef KSTDINT_H
2 #define KSTDINT_H
3 
4 #include <limits.h>
5 
6 /* Basic assumptions: 1) "char" is 8-bit; 2) there is a 8-bit, 16-bit, 32-bit
7  * and 64-bit integer type, respectively; 3) "short" is no less than "char",
8  * "int" is no less than "short", "long" is no less than "int" and "long long"
9  * is no less than "long"; 4) "int" is at least 16-bit, "long" at least 32-bit
10  * and "long long" at least 64-bit. The last two assumptions are enforced by
11  * the C99 spec.
12  *
13  * Following assumptions 1) and 2), we know that "signed char"=="int8_t" and
14  * "short"=="int16_t" for sure. Further from the assumptions, a 32-bit integer
15  * type must be either "int" or "long". We can test (UINT16_MAX==UINT_MAX) to
16  * see which is the case. Similarly, a 64-bit integer must be either "long" or
17  * "long long". We can test (UINT16_MAX==UINT_MAX) to get the definite answer.
18  */
19 
20 /* 8-bit integers */
21 typedef signed char int8_t;
22 typedef unsigned char uint8_t;
23 #define INT8_MIN (-SCHAR_MAX-1)
24 #define INT8_MAX SCHAR_MAX
25 #define UINT8_MAX UCHAR_MAX
26 
27 /* 16-bit integers */
28 typedef signed short int16_t;
29 typedef unsigned short uint16_t;
30 #define INT16_MIN (-SHRT_MAX-1)
31 #define INT16_MAX SHRT_MAX
32 #define UINT16_MAX USHRT_MAX
33 
34 /* 32-bit integers */
35 #if UINT16_MAX != UINT_MAX
36 typedef signed int int32_t;
37 typedef unsigned int uint32_t;
38 #define INT32_MIN (-INT_MAX-1)
39 #define INT32_MAX INT_MAX
40 #define UINT32_MAX UINT_MAX
41 #else /* then int is 16-bit and long is 32-bit, which may happen to compilers for embedded CPUs */
42 typedef signed long int32_t;
43 typedef unsigned long uint32_t;
44 #define INT32_MIN (-LONG_MAX-1)
45 #define INT32_MAX LONG_MAX
46 #define UINT32_MAX ULONG_MAX
47 #endif /* ~UINT16_MAX!=UINT_MAX */
48 
49 /* 64-bit integers */
50 #if UINT32_MAX != ULONG_MAX
51 typedef signed long int64_t;
52 typedef unsigned long uint64_t;
53 #define INT64_MIN (-LONG_MAX-1)
54 #define INT64_MAX LONG_MAX
55 #define UINT64_MAX ULONG_MAX
56 #else
57 typedef signed long long int64_t;
58 typedef unsigned long long uint64_t;
59 #define INT64_MIN (-LLONG_MAX-1)
60 #define INT64_MAX LLONG_MAX
61 #define UINT64_MAX ULLONG_MAX
62 #endif /* ~UINT32_MAX!=ULONG_MAX */
63 
64 #endif /* ~defined(KSTDINT_H) */