1 /* 2 * Copyright (c) 2014, STMicroelectronics International N.V. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 /* 29 * This file provides what C99 standard requires in 30 * 7.18 interger types <stdint.h> 31 */ 32 33 #ifndef STDINT_H 34 #define STDINT_H 35 #define _STDINT_H 36 37 /* 38 * If compiler supplies neither __ILP32__ or __LP64__, try to figure it out 39 * here. 40 */ 41 #if !defined(__ILP32__) && !defined(__LP64__) 42 #if defined(__SIZEOF_INT__) && defined(__SIZEOF_POINTER__) && \ 43 defined(__SIZEOF_LONG__) 44 #if __SIZEOF_INT__ == 4 && __SIZEOF_POINTER__ == 4 && __SIZEOF_LONG__ == 4 45 #define __ILP32__ 1 46 #endif 47 #if __SIZEOF_INT__ == 4 && __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 8 48 #define __LP64__ 1 49 #endif 50 #endif 51 #endif /* !defined(__ILP32__) && !defined(__LP64__) */ 52 53 #if !defined(__ILP32__) && !defined(__LP64__) 54 #error Neither __ILP32__ nor __LP64__ is defined 55 #endif 56 57 #ifndef ASM 58 59 /* 7.18.1.1 Exact-width interger types */ 60 #ifndef __int8_t_defined 61 # define __int8_t_defined 62 typedef signed char int8_t; 63 typedef short int int16_t; 64 typedef int int32_t; 65 #ifdef __ILP32__ 66 __extension__ 67 typedef long long int int64_t; 68 #endif /*__ILP32__*/ 69 #ifdef __LP64__ 70 typedef long int int64_t; 71 #endif /*__LP64__*/ 72 #endif 73 74 /* Unsigned. */ 75 typedef unsigned char uint8_t; 76 typedef unsigned short int uint16_t; 77 #ifndef __uint32_t_defined 78 typedef unsigned int uint32_t; 79 # define __uint32_t_defined 80 #endif 81 #ifdef __ILP32__ 82 __extension__ 83 typedef unsigned long long int uint64_t; 84 #endif /*__ILP32__*/ 85 #ifdef __LP64__ 86 typedef unsigned long int uint64_t; 87 #endif /*__LP64__*/ 88 89 /* 7.18.1.2 Minimum-width integer types */ 90 typedef int8_t int_least8_t; 91 typedef int16_t int_least16_t; 92 typedef int32_t int_least32_t; 93 typedef int64_t int_least64_t; 94 typedef uint8_t uint_least8_t; 95 typedef uint16_t uint_least16_t; 96 typedef uint32_t uint_least32_t; 97 typedef uint64_t uint_least64_t; 98 99 /* 7.18.1.3 Fastest minimum-width integer types */ 100 typedef int8_t int_fast8_t; 101 typedef int16_t int_fast16_t; 102 typedef int32_t int_fast32_t; 103 typedef int64_t int_fast64_t; 104 typedef uint8_t uint_fast8_t; 105 typedef uint16_t uint_fast16_t; 106 typedef uint32_t uint_fast32_t; 107 typedef uint64_t uint_fast64_t; 108 109 /* 7.18.1.4 Integer types capable of holding object pointers */ 110 typedef long intptr_t; 111 typedef unsigned long uintptr_t; 112 113 typedef int64_t intmax_t; 114 typedef uint64_t uintmax_t; 115 116 #endif /*ASM*/ 117 118 /* 119 * 7.18.2 Limits of specified-width integer types 120 */ 121 122 /* 7.18.2.1 Limits of exact-width interger types */ 123 124 #define INT8_MIN (-0x7f-1) 125 #define INT16_MIN (-0x7fff-1) 126 #define INT32_MIN (-0x7fffffff-1) 127 #define INT64_MIN (-0x7fffffffffffffffL-1) 128 129 #define INT8_MAX 0x7f 130 #define INT16_MAX 0x7fff 131 #define INT32_MAX 0x7fffffff 132 #define INT64_MAX 0x7fffffffffffffffL 133 134 #define UINT8_MAX 0xff 135 #define UINT16_MAX 0xffff 136 #define UINT32_MAX 0xffffffffU 137 #define UINT64_MAX 0xffffffffffffffffUL 138 139 /* 7.18.2.2 Limits of minimum-width integer types */ 140 141 #define INT_LEAST8_MIN INT8_MIN 142 #define INT_LEAST16_MIN INT16_MIN 143 #define INT_LEAST32_MIN INT32_MIN 144 #define INT_LEAST64_MIN INT64_MIN 145 146 #define INT_LEAST8_MAX INT8_MAX 147 #define INT_LEAST16_MAX INT16_MAX 148 #define INT_LEAST32_MAX INT32_MAX 149 #define INT_LEAST64_MAX INT64_MAX 150 151 #define UINT_LEAST8_MAX UINT8_MAX 152 #define UINT_LEAST16_MAX UINT16_MAX 153 #define UINT_LEAST32_MAX UINT32_MAX 154 #define UINT_LEAST64_MAX UINT64_MAX 155 156 /* 7.18.2.3 Limits of fastest minimum-width integer types */ 157 158 #define INT_FAST8_MIN INT8_MIN 159 #define INT_FAST16_MIN INT16_MIN 160 #define INT_FAST32_MIN INT32_MIN 161 #define INT_FAST64_MIN INT64_MIN 162 163 #define INT_FAST8_MAX INT8_MAX 164 #define INT_FAST16_MAX INT16_MAX 165 #define INT_FAST32_MAX INT32_MAX 166 #define INT_FAST64_MAX INT64_MAX 167 168 #define UINT_FAST8_MAX UINT8_MAX 169 #define UINT_FAST16_MAX UINT16_MAX 170 #define UINT_FAST32_MAX UINT32_MAX 171 #define UINT_FAST64_MAX UINT64_MAX 172 173 /* 7.18.2.4 Limits of integer types capable of holding object pointers */ 174 175 #define INTPTR_MIN LONG_MIN 176 #define INTPTR_MAX LONG_MAX 177 #define UINTPTR_MAX ULONG_MAX 178 179 /* 7.18.2.5 Limits of greatest-width integer types */ 180 #define INTMAX_MAX INT64_MAX 181 #define INTMAX_MIN INT64_MIN 182 #define UINTMAX_MAX UINT64_MAX 183 184 /* 7.18.3 Limits of other integer types */ 185 #define SIZE_MAX ULONG_MAX 186 187 /* 188 * 7.18.4 Macros for integer constants 189 */ 190 191 /* 7.18.4.1 Macros for minimum-width integer constants */ 192 193 #define INT8_C(v) v 194 #define UINT8_C(v) v 195 #define INT16_C(v) v 196 #define UINT16_C(v) v 197 #define INT32_C(v) v 198 #define UINT32_C(v) v ## U 199 #ifdef __ILP32__ 200 #define INT64_C(v) v ## LL 201 #define UINT64_C(v) v ## ULL 202 #endif 203 #ifdef __LP64__ 204 #define INT64_C(v) v ## L 205 #define UINT64_C(v) v ## UL 206 #endif 207 208 /* 7.18.4.2 Macros for greatest-width integer constants */ 209 210 #define INTMAX_C(v) INT64_C(v) 211 #define UINTMAX_C(v) UINT64_C(v) 212 213 214 #endif /* STDINT_H */ 215