1 /* 2 * Copyright (c) 2007 Patrick Mansfield <patmans@us.ibm.com> 3 */ 4 5 #ifndef _MACHINE__DEFAULT_TYPES_H 6 #define _MACHINE__DEFAULT_TYPES_H 7 8 #include <sys/features.h> 9 10 /* 11 * Guess on types by examining *_MIN / *_MAX defines. 12 */ 13 #if defined(__INT_MAX__) && defined(__LONG_MAX__) && defined (__SCHAR_MAX__) && defined (__SHRT_MAX__) 14 /* GCC >= 3.3.0 has __<val>__ implicitly defined. */ 15 #define __EXP(x) __##x##__ 16 #else 17 /* Fall back to POSIX versions from <limits.h> */ 18 #define __EXP(x) x 19 #include <limits.h> 20 #endif 21 22 /* Check if "long long" is 64bit wide */ 23 /* Modern GCCs provide __LONG_LONG_MAX__, SUSv3 wants LLONG_MAX */ 24 #if ( defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) ) \ 25 || ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) ) 26 #define __have_longlong64 1 27 #endif 28 29 /* Check if "long" is 64bit or 32bit wide */ 30 #if __EXP(LONG_MAX) > 0x7fffffff 31 #define __have_long64 1 32 #elif __EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__) 33 #define __have_long32 1 34 #endif 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #ifdef __INT8_TYPE__ 41 typedef __INT8_TYPE__ __int8_t; 42 #ifdef __UINT8_TYPE__ 43 typedef __UINT8_TYPE__ __uint8_t; 44 #else 45 typedef unsigned __INT8_TYPE__ __uint8_t; 46 #endif 47 #define ___int8_t_defined 1 48 #elif __EXP(SCHAR_MAX) == 0x7f 49 typedef signed char __int8_t ; 50 typedef unsigned char __uint8_t ; 51 #define ___int8_t_defined 1 52 #endif 53 54 #ifdef __INT16_TYPE__ 55 typedef __INT16_TYPE__ __int16_t; 56 #ifdef __UINT16_TYPE__ 57 typedef __UINT16_TYPE__ __uint16_t; 58 #else 59 typedef unsigned __INT16_TYPE__ __uint16_t; 60 #endif 61 #define ___int16_t_defined 1 62 #elif __EXP(INT_MAX) == 0x7fff 63 typedef signed int __int16_t; 64 typedef unsigned int __uint16_t; 65 #define ___int16_t_defined 1 66 #elif __EXP(SHRT_MAX) == 0x7fff 67 typedef signed short __int16_t; 68 typedef unsigned short __uint16_t; 69 #define ___int16_t_defined 1 70 #elif __EXP(SCHAR_MAX) == 0x7fff 71 typedef signed char __int16_t; 72 typedef unsigned char __uint16_t; 73 #define ___int16_t_defined 1 74 #endif 75 76 #ifdef __INT32_TYPE__ 77 typedef __INT32_TYPE__ __int32_t; 78 #ifdef __UINT32_TYPE__ 79 typedef __UINT32_TYPE__ __uint32_t; 80 #else 81 typedef unsigned __INT32_TYPE__ __uint32_t; 82 #endif 83 #define ___int32_t_defined 1 84 #elif __EXP(INT_MAX) == 0x7fffffffL 85 typedef signed int __int32_t; 86 typedef unsigned int __uint32_t; 87 #define ___int32_t_defined 1 88 #elif __EXP(LONG_MAX) == 0x7fffffffL 89 typedef signed long __int32_t; 90 typedef unsigned long __uint32_t; 91 #define ___int32_t_defined 1 92 #elif __EXP(SHRT_MAX) == 0x7fffffffL 93 typedef signed short __int32_t; 94 typedef unsigned short __uint32_t; 95 #define ___int32_t_defined 1 96 #elif __EXP(SCHAR_MAX) == 0x7fffffffL 97 typedef signed char __int32_t; 98 typedef unsigned char __uint32_t; 99 #define ___int32_t_defined 1 100 #endif 101 102 #ifdef __INT64_TYPE__ 103 typedef __INT64_TYPE__ __int64_t; 104 #ifdef __UINT64_TYPE__ 105 typedef __UINT64_TYPE__ __uint64_t; 106 #else 107 typedef unsigned __INT64_TYPE__ __uint64_t; 108 #endif 109 #define ___int64_t_defined 1 110 #elif __EXP(LONG_MAX) > 0x7fffffff 111 typedef signed long __int64_t; 112 typedef unsigned long __uint64_t; 113 #define ___int64_t_defined 1 114 115 /* GCC has __LONG_LONG_MAX__ */ 116 #elif defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) 117 typedef signed long long __int64_t; 118 typedef unsigned long long __uint64_t; 119 #define ___int64_t_defined 1 120 121 /* POSIX mandates LLONG_MAX in <limits.h> */ 122 #elif defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) 123 typedef signed long long __int64_t; 124 typedef unsigned long long __uint64_t; 125 #define ___int64_t_defined 1 126 127 #elif __EXP(INT_MAX) > 0x7fffffff 128 typedef signed int __int64_t; 129 typedef unsigned int __uint64_t; 130 #define ___int64_t_defined 1 131 #endif 132 133 #ifdef __INT_LEAST8_TYPE__ 134 typedef __INT_LEAST8_TYPE__ __int_least8_t; 135 #ifdef __UINT_LEAST8_TYPE__ 136 typedef __UINT_LEAST8_TYPE__ __uint_least8_t; 137 #else 138 typedef unsigned __INT_LEAST8_TYPE__ __uint_least8_t; 139 #endif 140 #define ___int_least8_t_defined 1 141 #elif defined(___int8_t_defined) 142 typedef __int8_t __int_least8_t; 143 typedef __uint8_t __uint_least8_t; 144 #define ___int_least8_t_defined 1 145 #elif defined(___int16_t_defined) 146 typedef __int16_t __int_least8_t; 147 typedef __uint16_t __uint_least8_t; 148 #define ___int_least8_t_defined 1 149 #elif defined(___int32_t_defined) 150 typedef __int32_t __int_least8_t; 151 typedef __uint32_t __uint_least8_t; 152 #define ___int_least8_t_defined 1 153 #elif defined(___int64_t_defined) 154 typedef __int64_t __int_least8_t; 155 typedef __uint64_t __uint_least8_t; 156 #define ___int_least8_t_defined 1 157 #endif 158 159 #ifdef __INT_LEAST16_TYPE__ 160 typedef __INT_LEAST16_TYPE__ __int_least16_t; 161 #ifdef __UINT_LEAST16_TYPE__ 162 typedef __UINT_LEAST16_TYPE__ __uint_least16_t; 163 #else 164 typedef unsigned __INT_LEAST16_TYPE__ __uint_least16_t; 165 #endif 166 #define ___int_least16_t_defined 1 167 #elif defined(___int16_t_defined) 168 typedef __int16_t __int_least16_t; 169 typedef __uint16_t __uint_least16_t; 170 #define ___int_least16_t_defined 1 171 #elif defined(___int32_t_defined) 172 typedef __int32_t __int_least16_t; 173 typedef __uint32_t __uint_least16_t; 174 #define ___int_least16_t_defined 1 175 #elif defined(___int64_t_defined) 176 typedef __int64_t __int_least16_t; 177 typedef __uint64_t __uint_least16_t; 178 #define ___int_least16_t_defined 1 179 #endif 180 181 #ifdef __INT_LEAST32_TYPE__ 182 typedef __INT_LEAST32_TYPE__ __int_least32_t; 183 #ifdef __UINT_LEAST32_TYPE__ 184 typedef __UINT_LEAST32_TYPE__ __uint_least32_t; 185 #else 186 typedef unsigned __INT_LEAST32_TYPE__ __uint_least32_t; 187 #endif 188 #define ___int_least32_t_defined 1 189 #elif defined(___int32_t_defined) 190 typedef __int32_t __int_least32_t; 191 typedef __uint32_t __uint_least32_t; 192 #define ___int_least32_t_defined 1 193 #elif defined(___int64_t_defined) 194 typedef __int64_t __int_least32_t; 195 typedef __uint64_t __uint_least32_t; 196 #define ___int_least32_t_defined 1 197 #endif 198 199 #ifdef __INT_LEAST64_TYPE__ 200 typedef __INT_LEAST64_TYPE__ __int_least64_t; 201 #ifdef __UINT_LEAST64_TYPE__ 202 typedef __UINT_LEAST64_TYPE__ __uint_least64_t; 203 #else 204 typedef unsigned __INT_LEAST64_TYPE__ __uint_least64_t; 205 #endif 206 #define ___int_least64_t_defined 1 207 #elif defined(___int64_t_defined) 208 typedef __int64_t __int_least64_t; 209 typedef __uint64_t __uint_least64_t; 210 #define ___int_least64_t_defined 1 211 #endif 212 213 #if defined(__INTMAX_TYPE__) 214 typedef __INTMAX_TYPE__ __intmax_t; 215 #elif __have_longlong64 216 typedef signed long long __intmax_t; 217 #else 218 typedef signed long __intmax_t; 219 #endif 220 221 #if defined(__UINTMAX_TYPE__) 222 typedef __UINTMAX_TYPE__ __uintmax_t; 223 #elif __have_longlong64 224 typedef unsigned long long __uintmax_t; 225 #else 226 typedef unsigned long __uintmax_t; 227 #endif 228 229 #ifdef __INTPTR_TYPE__ 230 typedef __INTPTR_TYPE__ __intptr_t; 231 #ifdef __UINTPTR_TYPE__ 232 typedef __UINTPTR_TYPE__ __uintptr_t; 233 #else 234 typedef unsigned __INTPTR_TYPE__ __uintptr_t; 235 #endif 236 #elif defined(__PTRDIFF_TYPE__) 237 typedef __PTRDIFF_TYPE__ __intptr_t; 238 typedef unsigned __PTRDIFF_TYPE__ __uintptr_t; 239 #else 240 typedef long __intptr_t; 241 typedef unsigned long __uintptr_t; 242 #endif 243 244 #undef __EXP 245 246 #ifdef __cplusplus 247 } 248 #endif 249 250 #endif /* _MACHINE__DEFAULT_TYPES_H */ 251