blob: ffe059dd63bba6a5ec75ff8be6d50e23132190e8 [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Jacob Garber0c4ed4b2019-07-04 12:55:35 -06002
3#ifndef STDINT_H
4#define STDINT_H
5
Jacob Garber0c4ed4b2019-07-04 12:55:35 -06006/* Fixed width integer types */
7typedef signed char int8_t;
8typedef unsigned char uint8_t;
9
10typedef signed short int16_t;
11typedef unsigned short uint16_t;
12
13typedef signed int int32_t;
14typedef unsigned int uint32_t;
15
Jacob Garber0c4ed4b2019-07-04 12:55:35 -060016typedef signed long long int64_t;
17typedef unsigned long long uint64_t;
Jacob Garber0c4ed4b2019-07-04 12:55:35 -060018
19/* Types for 'void *' pointers */
20typedef signed long intptr_t;
21typedef unsigned long uintptr_t;
22
23/* Ensure that the widths are all correct */
Jacob Garber0c4ed4b2019-07-04 12:55:35 -060024_Static_assert(sizeof(int8_t) == 1, "Size of int8_t is incorrect");
25_Static_assert(sizeof(uint8_t) == 1, "Size of uint8_t is incorrect");
26
27_Static_assert(sizeof(int16_t) == 2, "Size of int16_t is incorrect");
28_Static_assert(sizeof(uint16_t) == 2, "Size of uint16_t is incorrect");
29
30_Static_assert(sizeof(int32_t) == 4, "Size of int32_t is incorrect");
31_Static_assert(sizeof(uint32_t) == 4, "Size of uint32_t is incorrect");
32
33_Static_assert(sizeof(int64_t) == 8, "Size of int64_t is incorrect");
34_Static_assert(sizeof(uint64_t) == 8, "Size of uint64_t is incorrect");
35
36_Static_assert(sizeof(intptr_t) == sizeof(void *), "Size of intptr_t is incorrect");
37_Static_assert(sizeof(uintptr_t) == sizeof(void *), "Size of uintptr_t is incorrect");
Jacob Garber0c4ed4b2019-07-04 12:55:35 -060038
39/* Maximum width integer types */
Jacob Garber0c4ed4b2019-07-04 12:55:35 -060040typedef int64_t intmax_t;
41typedef uint64_t uintmax_t;
Jacob Garber0c4ed4b2019-07-04 12:55:35 -060042
43/* Convenient typedefs */
44typedef int8_t s8;
45typedef uint8_t u8;
46
47typedef int16_t s16;
48typedef uint16_t u16;
49
50typedef int32_t s32;
51typedef uint32_t u32;
52
Jacob Garber0c4ed4b2019-07-04 12:55:35 -060053typedef int64_t s64;
54typedef uint64_t u64;
Jacob Garber0c4ed4b2019-07-04 12:55:35 -060055
56/* Limits of integer types */
57#define INT8_MIN ((int8_t)0x80)
58#define INT8_MAX ((int8_t)0x7F)
59#define UINT8_MAX ((uint8_t)0xFF)
60
61#define INT16_MIN ((int16_t)0x8000)
62#define INT16_MAX ((int16_t)0x7FFF)
63#define UINT16_MAX ((uint16_t)0xFFFF)
64
65#define INT32_MIN ((int32_t)0x80000000)
66#define INT32_MAX ((int32_t)0x7FFFFFFF)
67#define UINT32_MAX ((uint32_t)0xFFFFFFFF)
68
Jacob Garber0c4ed4b2019-07-04 12:55:35 -060069#define INT64_MIN ((int64_t)0x8000000000000000)
70#define INT64_MAX ((int64_t)0x7FFFFFFFFFFFFFFF)
71#define UINT64_MAX ((uint64_t)0xFFFFFFFFFFFFFFFF)
Jacob Garber0c4ed4b2019-07-04 12:55:35 -060072
Jacob Garber0c4ed4b2019-07-04 12:55:35 -060073#define INTMAX_MIN INT64_MIN
74#define INTMAX_MAX INT64_MAX
75#define UINTMAX_MAX UINT64_MAX
Jacob Garber0c4ed4b2019-07-04 12:55:35 -060076
Jacob Garber0c4ed4b2019-07-04 12:55:35 -060077#endif /* STDINT_H */