ADTF  3.18.3
a_utils_portable_types.h
Go to the documentation of this file.
1 
7 #ifndef _A_UTILS_PORTABLE_TYPES_H_
8 #define _A_UTILS_PORTABLE_TYPES_H_
9 
10 #include <stddef.h>
11 #include <limits.h>
12 #include <signal.h>
13 
14 #ifndef SIZE_MAX
15 # define SIZE_MAX (~(size_t)0)
16 #endif
17 
18 /*
19  * Deduce the type assignments from limits.h under the assumption that
20  * integer sizes in bits are powers of 2, and follow the ANSI
21  * definitions.
22  */
23 
24 #ifndef UINT8_MAX
25 # define UINT8_MAX 0xff
26 #endif
27 #ifndef tUInt8
28 # if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
29  typedef unsigned char tUInt8;
30 # else
31 # error "Platform not supported"
32 # endif
33 #endif
34 
35 #ifndef INT8_MAX
36 # define INT8_MAX 0x7f
37 #endif
38 #ifndef INT8_MIN
39 # define INT8_MIN A_UTILS_INT8_C(0x80)
40 #endif
41 #ifndef tInt8
42 # if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
43  typedef signed char tInt8;
44 # define A_UTILS_INT8_C(v) ((tInt8) v)
45 # else
46 # error "Platform not supported"
47 # endif
48 #endif
49 
50 #ifndef UINT16_MAX
51 # define UINT16_MAX 0xffff
52 #endif
53 #ifndef tUInt16
54 #if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
55  typedef unsigned int tUInt16;
56 #elif (USHRT_MAX == UINT16_MAX)
57  typedef unsigned short tUInt16;
58 #else
59 #error "Platform not supported"
60 #endif
61 #endif
62 
63 #ifndef INT16_MAX
64 # define INT16_MAX 0x7fff
65 #endif
66 #ifndef INT16_MIN
67 # define INT16_MIN A_UTILS_INT16_C(0x8000)
68 #endif
69 #ifndef tInt16
70 #if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
71  typedef signed int tInt16;
72 # define A_UTILS_INT16_C(v) ((tInt16) (v))
73 #elif (SHRT_MAX == INT16_MAX)
74  typedef signed short tInt16;
75 # define A_UTILS_INT16_C(v) ((tInt16) (v))
76 #else
77 #error "Platform not supported"
78 #endif
79 #endif
80 
81 #ifndef UINT32_MAX
82 # define UINT32_MAX (0xffffffffUL)
83 #endif
84 #ifndef tUInt32
85 #if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
86  typedef unsigned long tUInt32;
87 #elif (UINT_MAX == UINT32_MAX)
88  typedef unsigned int tUInt32;
89 #elif (USHRT_MAX == UINT32_MAX)
90  typedef unsigned short tUInt32;
91 #else
92 #error "Platform not supported"
93 #endif
94 #endif
95 
96 #ifndef INT32_MAX
97 # define INT32_MAX (0x7fffffffL)
98 #endif
99 #ifndef INT32_MIN
100 # define INT32_MIN A_UTILS_INT32_C(0x80000000)
101 #endif
102 #ifndef tInt32
103 #if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
104  typedef signed long tInt32;
105 # define A_UTILS_INT32_C(v) v ## L
106 #elif (INT_MAX == INT32_MAX)
107  typedef signed int tInt32;
108 # define A_UTILS_INT32_C(v) v
109 #elif (SHRT_MAX == INT32_MAX)
110  typedef signed short tInt32;
111 # define A_UTILS_INT32_C(v) ((short) (v))
112 #else
113 #error "Platform not supported"
114 #endif
115 #endif
116 
117 /*
118  * The macro a_utils_stdint_int64_defined is temporarily used to record
119  * whether or not 64 integer support is available. It must be
120  * defined for any 64 integer extensions for new platforms that are
121  * added.
122  */
123 
124 #if !defined (a_utils_stdint_int64_defined)
125 #if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
126 # if (__STDC__ && __STDC_VERSION >= 199901L) || defined (S_SPLINT_S)
127 # define a_utils_stdint_int64_defined
128  typedef long long tInt64;
129  typedef unsigned long long tUInt64;
130 # define A_UTILS_UINT64_C(v) v ## ULL
131 # define A_UTILS_INT64_C(v) v ## LL
132 # endif
133 #endif
134 #endif
135 
136 #if !defined (a_utils_stdint_int64_defined)
137 # if defined(__GNUC__)
138 # define a_utils_stdint_int64_defined
139  __extension__ typedef long long tInt64;
140  __extension__ typedef unsigned long long tUInt64;
141 # define A_UTILS_UINT64_C(v) v ## ULL
142 # define A_UTILS_INT64_C(v) v ## LL
143 # elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S) || defined (A_UTILS_PLATFORM_WITH_STDINT_INT64)
144 # define a_utils_stdint_int64_defined
145  typedef long long tInt64;
146  typedef unsigned long long tUInt64;
147 # define A_UTILS_UINT64_C(v) v ## ULL
148 # define A_UTILS_INT64_C(v) v ## LL
149 # elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
150 # define a_utils_stdint_int64_defined
151  typedef __int64 tInt64;
152  typedef unsigned __int64 tUInt64;
153 # define A_UTILS_UINT64_C(v) v ## UI64
154 # define A_UTILS_INT64_C(v) v ## I64
155 # endif
156 #endif
157 
158 #ifndef a_utils_stdint_int64_defined
159 # error "Platform not supported"
160 #endif
161 
162 #if !defined (LONG_LONG_MAX) && defined (A_UTILS_INT64_C)
163 # define LONG_LONG_MAX A_UTILS_INT64_C (9223372036854775807)
164 #endif
165 #ifndef ULONG_LONG_MAX
166 # define ULONG_LONG_MAX A_UTILS_UINT64_C (18446744073709551615)
167 #endif
168 
169 #if !defined (INT64_MAX) && defined (A_UTILS_INT64_C)
170 # define INT64_MAX A_UTILS_INT64_C (9223372036854775807)
171 #endif
172 #if !defined (INT64_MIN) && defined (A_UTILS_INT64_C)
173 # define INT64_MIN A_UTILS_INT64_C (-9223372036854775808)
174 #endif
175 #if !defined (UINT64_MAX) && defined (A_UTILS_INT64_C)
176 # define UINT64_MAX A_UTILS_UINT64_C (18446744073709551615)
177 #endif
178 
179 #endif
uint8_t tUInt8
type definition for unsigned integer values (8bit) (platform and compiler independent type).
int64_t tInt64
type definition for signed integer values (64bit) (platform and compiler independent type).
int16_t tInt16
type definition for signed integer values (16bit) (platform and compiler independent type).
int32_t tInt32
type definition for signed integer values (32bit) (platform and compiler independent type).
uint16_t tUInt16
type definition for unsigned integer values (16bit) (platform and compiler independent type).
uint32_t tUInt32
type definition for unsigned integer values (32bit) (platform and compiler independent type).
int8_t tInt8
type definition for signed integer values (8bit) (platform and compiler independent type).
uint64_t tUInt64
type definition for unsigned integer values (64bit) (platform and compiler independent type).