stdint.h revision 40e60c27d09d0561cd3ab41c332e3b0838e899dd
1/*===---- stdint.h - Standard header for sized integer types --------------===*\ 2 * 3 * Copyright (c) 2009 Chris Lattner 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy 6 * of this software and associated documentation files (the "Software"), to deal 7 * in the Software without restriction, including without limitation the rights 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 * copies of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 * THE SOFTWARE. 22 * 23\*===----------------------------------------------------------------------===*/ 24 25#ifndef __STDINT_H 26#define __STDINT_H 27 28/* We currently only support targets with power of two, 2s complement integers. 29 */ 30 31/* C99 7.18.1.1 Exact-width integer types. 32 * C99 7.18.1.2 Minimum-width integer types. 33 * C99 7.18.1.3 Fastest minimum-width integer types. 34 * Since we only support pow-2 targets, these map directly to exact width types. 35 */ 36 37typedef signed __INT8_TYPE__ int8_t; 38typedef unsigned __INT8_TYPE__ uint8_t; 39typedef int8_t int_least8_t; 40typedef uint8_t uint_least8_t; 41typedef int8_t int_fast8_t; 42typedef uint8_t uint_fast8_t; 43 44typedef __INT16_TYPE__ int16_t; 45typedef unsigned __INT16_TYPE__ uint16_t; 46typedef int16_t int_least16_t; 47typedef uint16_t uint_least16_t; 48typedef int16_t int_fast16_t; 49typedef uint16_t uint_fast16_t; 50 51typedef __INT32_TYPE__ int32_t; 52typedef unsigned __INT32_TYPE__ uint32_t; 53typedef int32_t int_least32_t; 54typedef uint32_t uint_least32_t; 55typedef int32_t int_fast32_t; 56typedef uint32_t uint_fast32_t; 57 58/* Some 16-bit targets do not have a 64-bit datatype. Only define the 64-bit 59 * typedefs if there is something to typedef them to. 60 */ 61#ifdef __INT64_TYPE__ 62typedef __INT64_TYPE__ int64_t; 63typedef unsigned __INT64_TYPE__ uint64_t; 64typedef int64_t int_least64_t; 65typedef uint64_t uint_least64_t; 66typedef int64_t int_fast64_t; 67typedef uint64_t uint_fast64_t; 68#endif 69 70 71/* C99 7.18.1.4 Integer types capable of holding object pointers. 72 */ 73#ifndef __intptr_t_defined 74typedef __INTPTR_TYPE__ intptr_t; 75typedef unsigned __INTPTR_TYPE__ uintptr_t; 76#define __intptr_t_defined 77#endif 78 79/* C99 7.18.1.5 Greatest-width integer types. 80 */ 81typedef __INTMAX_TYPE__ intmax_t; 82typedef __UINTMAX_TYPE__ uintmax_t; 83 84/* C99 7.18.2.1 Limits of exact-width integer types. 85 * Fixed sized values have fixed size max/min. 86 * C99 7.18.2.2 Limits of minimum-width integer types. 87 * Since we map these directly onto fixed-sized types, these values the same. 88 * C99 7.18.2.3 Limits of fastest minimum-width integer types. 89 * 90 * Note that C++ should not check __STDC_LIMIT_MACROS here, contrary to the 91 * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]). 92 */ 93 94#define INT8_MAX 127 95#define INT8_MIN (-128) 96#define UINT8_MAX 255 97#define INT_LEAST8_MIN INT8_MIN 98#define INT_LEAST8_MAX INT8_MAX 99#define UINT_LEAST8_MAX UINT8_MAX 100#define INT_FAST8_MIN INT8_MIN 101#define INT_FAST8_MAX INT8_MAX 102#define UINT_FAST8_MAX UINT8_MAX 103 104#define INT16_MAX 32767 105#define INT16_MIN (-32768) 106#define UINT16_MAX 65535 107#define INT_LEAST16_MIN INT16_MIN 108#define INT_LEAST16_MAX INT16_MAX 109#define UINT_LEAST16_MAX UINT16_MAX 110#define INT_FAST16_MIN INT16_MIN 111#define INT_FAST16_MAX INT16_MAX 112#define UINT_FAST16_MAX UINT16_MAX 113 114#define INT32_MAX 2147483647 115#define INT32_MIN (-2147483647-1) 116#define UINT32_MAX 4294967295U 117#define INT_LEAST32_MIN INT32_MIN 118#define INT_LEAST32_MAX INT32_MAX 119#define UINT_LEAST32_MAX UINT32_MAX 120#define INT_FAST32_MIN INT32_MIN 121#define INT_FAST32_MAX INT32_MAX 122#define UINT_FAST32_MAX UINT32_MAX 123 124/* If we do not have 64-bit support, don't define the 64-bit size macros. */ 125#ifndef __INT64_TYPE__ 126#define INT64_MAX 9223372036854775807LL 127#define INT64_MIN (-9223372036854775807LL-1) 128#define UINT64_MAX 18446744073709551615ULL 129#define INT_LEAST64_MIN INT64_MIN 130#define INT_LEAST64_MAX INT64_MAX 131#define UINT_LEAST64_MAX UINT64_MAX 132#define INT_FAST64_MIN INT64_MIN 133#define INT_FAST64_MAX INT64_MAX 134#define UINT_FAST64_MAX UINT64_MAX 135#endif 136 137/* C99 7.18.2.4 Limits of integer types capable of holding object pointers. */ 138/* C99 7.18.3 Limits of other integer types. */ 139 140#if __POINTER_WIDTH__ == 64 141 142#define INTPTR_MIN INT64_MIN 143#define INTPTR_MAX INT64_MAX 144#define UINTPTR_MAX UINT64_MAX 145#define PTRDIFF_MIN INT64_MIN 146#define PTRDIFF_MAX INT64_MAX 147#define SIZE_MAX UINT64_MAX 148 149#elif __POINTER_WIDTH__ == 32 150 151#define INTPTR_MIN INT32_MIN 152#define INTPTR_MAX INT32_MAX 153#define UINTPTR_MAX UINT32_MAX 154#define PTRDIFF_MIN INT32_MIN 155#define PTRDIFF_MAX INT32_MAX 156#define SIZE_MAX UINT32_MAX 157 158#elif __POINTER_WIDTH__ == 16 159 160#define INTPTR_MIN INT16_MIN 161#define INTPTR_MAX INT16_MAX 162#define UINTPTR_MAX UINT16_MAX 163#define PTRDIFF_MIN INT16_MIN 164#define PTRDIFF_MAX INT16_MAX 165#define SIZE_MAX UINT16_MAX 166 167#else 168#error "unknown or unset pointer width!" 169#endif 170 171/* C99 7.18.2.5 Limits of greatest-width integer types. */ 172#define INTMAX_MIN (-__INTMAX_MAX__-1) 173#define INTMAX_MAX __INTMAX_MAX__ 174#define UINTMAX_MAX (__INTMAX_MAX__*2ULL+1ULL) 175 176/* C99 7.18.3 Limits of other integer types. */ 177#define SIG_ATOMIC_MIN INT32_MIN 178#define SIG_ATOMIC_MAX INT32_MAX 179#define WINT_MIN INT32_MIN 180#define WINT_MAX INT32_MAX 181 182/* FIXME: if we ever support a target with unsigned wchar_t, this should be 183 * 0 .. Max. 184 */ 185#ifndef WCHAR_MAX 186#define WCHAR_MAX __WCHAR_MAX__ 187#endif 188#ifndef WCHAR_MIN 189#define WCHAR_MIN (-__WCHAR_MAX__-1) 190#endif 191 192/* C99 7.18.4 Macros for minimum-width integer constants. 193 * 194 * Note that C++ should not check __STDC_CONSTANT_MACROS here, contrary to the 195 * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]). 196 */ 197 198#define INT8_C(v) (v) 199#define UINT8_C(v) (v##U) 200#define INT16_C(v) (v) 201#define UINT16_C(v) (v##U) 202#define INT32_C(v) (v) 203#define UINT32_C(v) (v##U) 204 205/* Only define the 64-bit size macros if we have 64-bit support. */ 206#ifdef __INT64_TYPE__ 207#define INT64_C(v) (v##LL) 208#define UINT64_C(v) (v##ULL) 209#endif 210 211/* 7.18.4.2 Macros for greatest-width integer constants. */ 212#define INTMAX_C(v) (v##LL) 213#define UINTMAX_C(v) (v##ULL) 214 215#endif /* __STDINT_H */ 216