-
Notifications
You must be signed in to change notification settings - Fork 52
/
int.h
215 lines (165 loc) · 4.96 KB
/
int.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
* int - integer types and integer macros used in calc
*
* For general information on C integers, see:
*
* https://en.cppreference.com/w/c/language/arithmetic_types
* https://en.cppreference.com/w/c/types/integer
*
* Copyright (C) 2023 Landon Curt Noll
*
* Primary author: Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* Calc is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* A copy of version 2.1 of the GNU Lesser General Public License is
* distributed with calc under the filename COPYING-LGPL. You should have
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Under source code control: 2023/08/22 21:14:25
* File existed as early as: 2023
*
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
#if !defined(INCLUDE_INT_H)
#define INCLUDE_INT_H
/*
* important include files that have an impact in integer types used in calc
*/
#include "have_stdint.h"
#if defined(HAVE_STDINT_H)
#include <stdint.h>
#endif /* HAVE_STDINT_H */
#include "have_inttypes.h"
#if defined(HAVE_INTTYPES_H)
#include <inttypes.h>
#endif /* HAVE_INTTYPES_H */
#include "status.chk_c.h"
#include "bool.h"
#include "charbit.h"
#include "version.h"
/*
* case: C compiler and select include files appear to meet calc requirements
*/
#if defined(CHK_C)
/*
* bit width of various signed integers
*
* These are standard for c23 or later.
* Compute them for earlier compiler standards.
*/
#if !defined(INT8_WIDTH)
#define INT8_WIDTH (sizeof(int8_t) * CALC_CHARBIT)
#endif /* INT8_WIDTH */
#if !defined(INT16_WIDTH)
#define INT16_WIDTH (sizeof(int16_t) * CALC_CHARBIT)
#endif /* INT16_WIDTH */
#if !defined(INT32_WIDTH)
#define INT32_WIDTH (sizeof(int32_t) * CALC_CHARBIT)
#endif /* INT32_WIDTH */
#if !defined(INT64_WIDTH)
#define INT64_WIDTH (sizeof(int64_t) * CALC_CHARBIT)
#endif /* INT64_WIDTH */
#if !defined(INTPTR_WIDTH)
#define INTPTR_WIDTH (sizeof(intptr_t) * CALC_CHARBIT)
#endif /* INTPTR_WIDTH */
#if !defined(INTMAX_WIDTH)
#define INTMAX_WIDTH (sizeof(intmax_t) * CALC_CHARBIT)
#endif /* INTMAX_WIDTH */
/*
* bit width of various unsigned integers
*
* These are standard for c23 or later.
* Compute them for earlier compiler standards.
*/
#if !defined(UINT8_WIDTH)
#define UINT8_WIDTH (sizeof(uint8_t) * CALC_CHARBIT)
#endif /* UINT8_WIDTH */
#if !defined(UINT16_WIDTH)
#define UINT16_WIDTH (sizeof(uint16_t) * CALC_CHARBIT)
#endif /* UINT16_WIDTH */
#if !defined(UINT32_WIDTH)
#define UINT32_WIDTH (sizeof(uint32_t) * CALC_CHARBIT)
#endif /* UINT32_WIDTH */
#if !defined(UINT64_WIDTH)
#define UINT64_WIDTH (sizeof(uint64_t) * CALC_CHARBIT)
#endif /* UINT64_WIDTH */
#if !defined(UINTPTR_WIDTH)
#define UINTPTR_WIDTH (sizeof(uintptr_t) * CALC_CHARBIT)
#endif /* UINTPTR_WIDTH */
#if !defined(UINTMAX_WIDTH)
#define UINTMAX_WIDTH (sizeof(uintmax_t) * CALC_CHARBIT)
#endif /* UINTMAX_WIDTH */
/*
* case: C compiler and/or select include files do not meet calc requirements
*/
#else /* CHK_C */
/*
* calc v2 is the last version where one might be able to use an old C compiler
* and/or tolerate missing include files
*/
#if MAJOR_VER < 3
/*
* bit width of various signed integers
*
* These are standard for c23 or later.
* Compute them for earlier compiler standards.
*/
#if !defined(INT8_WIDTH)
#define INT8_WIDTH (8)
#endif /* INT8_WIDTH */
#if !defined(INT16_WIDTH)
#define INT16_WIDTH (16)
#endif /* INT16_WIDTH */
#if !defined(INT32_WIDTH)
#define INT32_WIDTH (32)
#endif /* INT32_WIDTH */
#if !defined(INT64_WIDTH)
#define INT64_WIDTH (64)
#endif /* INT64_WIDTH */
#if !defined(INTPTR_WIDTH)
#define INTPTR_WIDTH (64)
#endif /* INTPTR_WIDTH */
#if !defined(INTMAX_WIDTH)
#define INTMAX_WIDTH (64)
#endif /* INTMAX_WIDTH */
/*
* bit width of various unsigned integers
*
* These are standard for c23 or later.
* Compute them for earlier compiler standards.
*/
#if !defined(UINT8_WIDTH)
#define UINT8_WIDTH (8)
#endif /* UINT8_WIDTH */
#if !defined(UINT16_WIDTH)
#define UINT16_WIDTH (16)
#endif /* UINT16_WIDTH */
#if !defined(UINT32_WIDTH)
#define UINT32_WIDTH (32)
#endif /* UINT32_WIDTH */
#if !defined(UINT64_WIDTH)
#define UINT64_WIDTH (64)
#endif /* UINT64_WIDTH */
#if !defined(UINTPTR_WIDTH)
#define UINTPTR_WIDTH (64)
#endif /* UINTPTR_WIDTH */
#if !defined(UINTMAX_WIDTH)
#define UINTMAX_WIDTH (64)
#endif /* UINTMAX_WIDTH */
#else /* MAJOR_VER < 3 */
/*
* calc v3 or later and CHK_C is undefined
*/
#pragma GCC error "calc v3 and later require C compiler and include files that support CHK_C"
#endif /* MAJOR_VER < 3 */
#endif /* CHK_C */
#endif /* !INCLUDE_INT_H */