NCBI C++ ToolKit
ncbitype.h
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CORELIB___NCBITYPE__H
2 #define CORELIB___NCBITYPE__H
3 
4 /* $Id: ncbitype.h 55773 2012-09-24 14:15:47Z ucko $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Denis Vakatov
30  *
31  *
32  */
33 
34 /**
35  * @file ncbitype.h
36  *
37  * Defines NCBI C/C++ fixed-size types.
38  *
39  * - Char, Uchar
40  * - Int1, Uint1
41  * - Int2, Uint2
42  * - Int4, Uint4
43  * - Int8, Uint8
44  * - Ncbi_BigScalar
45  * - Macros for constant values definition.
46  *
47  */
48 
49 /** @addtogroup Portability
50  *
51  * @{
52  */
53 
54 #include <ncbiconf.h>
55 
56 #ifdef HAVE_INTTYPES_H
57 # ifndef __STDC_CONSTANT_MACROS
58 # define __STDC_CONSTANT_MACROS
59 # endif /*!__STDC_CONSTANT_MACROS*/
60 # ifndef __STDC_FORMAT_MACROS
61 # define __STDC_FORMAT_MACROS
62 # endif /*!__STDC_FORMAT_MACROS*/
63 # include <inttypes.h>
64 #endif
65 
66 
67 /* Char, Uchar, Int[1,2,4], Uint[1,2,4]
68  */
69 
70 #if (SIZEOF_CHAR != 1)
71 # error "Unsupported size of char(must be 1 byte)"
72 #endif
73 #if (SIZEOF_SHORT != 2)
74 # error "Unsupported size of short int(must be 2 bytes)"
75 #endif
76 #if (SIZEOF_INT != 4)
77 # error "Unsupported size of int(must be 4 bytes)"
78 #endif
79 
80 #ifdef Int1
81 # undef Int1
82 # undef Uint1
83 # undef Int2
84 # undef Uint2
85 # undef Int4
86 # undef Uint4
87 #endif
88 #ifdef Int8
89 # undef Int8
90 # undef Uint8
91 #endif
92 
93 typedef char Char; /**< Alias for char */
94 typedef signed char Schar; /**< Alias for signed char */
95 typedef unsigned char Uchar; /**< Alias for unsigned char */
96 
97 #ifdef HAVE_INTTYPES_H
98 typedef int8_t Int1; /**< 1-byte (8-bit) signed integer */
99 typedef uint8_t Uint1; /**< 1-byte (8-bit) unsigned integer */
100 typedef int16_t Int2; /**< 2-byte (16-bit) signed integer */
101 typedef uint16_t Uint2; /**< 2-byte (16-bit) unsigned integer */
102 typedef int32_t Int4; /**< 4-byte (32-bit) signed integer */
103 typedef uint32_t Uint4; /**< 4-byte (32-bit) unsigned integer */
104 typedef int64_t Int8; /**< 8-byte (64-bit) signed integer */
105 typedef uint64_t Uint8; /**< 8-byte (64-bit) unsigned integer */
106 /* We still need to know (u)int64_t's ultimate type when defining functions
107  * or operators with one variant per distinct integral type. :-/ */
108 # if SIZEOF_LONG == 8 && !defined(NCBI_OS_DARWIN)
109 # define NCBI_INT8_IS_LONG 1
110 # elif SIZEOF_LONG_LONG == 8
111 # define NCBI_INT8_IS_LONG_LONG 1
112 # elif SIZEOF___INT64 == 8
113 # define NCBI_INT8_IS_INT64 1
114 # endif
115 #else
116 typedef signed char Int1; /**< Alias for signed char */
117 typedef unsigned char Uint1; /**< Alias for unsigned char */
118 typedef signed short Int2; /**< Alias for signed short */
119 typedef unsigned short Uint2; /**< Alias for unsigned short */
120 typedef signed int Int4; /**< Alias for signed int */
121 typedef unsigned int Uint4; /**< Alias for unsigned int */
122 
123 
124 /* Int8, Uint8
125  */
126 
127 # if (SIZEOF_LONG == 8)
128 # define NCBI_INT8_TYPE long
129 # define NCBI_INT8_IS_LONG 1
130 # elif (SIZEOF_LONG_LONG == 8)
131 # define NCBI_INT8_TYPE long long
132 # define NCBI_INT8_IS_LONG_LONG 1
133 # elif (SIZEOF___INT64 == 8)
134 # define NCBI_INT8_TYPE __int64
135 # define NCBI_INT8_IS_INT64 1
136 /** @deprecated Use NCBI_INT8_IS_INT64 instead */
137 # define NCBI_USE_INT64 1
138 # else
139 # error "This platform does not support 8-byte integer"
140 # endif
141 
142 /** Signed 8 byte sized integer */
143 typedef signed NCBI_INT8_TYPE Int8;
144 
145 /** Unsigned 8 byte sized integer */
146 typedef unsigned NCBI_INT8_TYPE Uint8;
147 
148 #endif /* HAVE_INTTYPES_H */
149 
150 /* BigScalar
151  */
152 
153 #define NCBI_BIG_TYPE Int8
154 #define SIZEOF_NCBI_BIG 8
155 #if (SIZEOF_LONG_DOUBLE > SIZEOF_NCBI_BIG)
156 # undef NCBI_BIG_TYPE
157 # undef SIZEOF_NCBI_BIG
158 # define NCBI_BIG_TYPE long double
159 # define SIZEOF_NCBI_BIG SIZEOF_LONG_DOUBLE
160 #endif
161 #if (SIZEOF_DOUBLE > SIZEOF_NCBI_BIG)
162 # undef NCBI_BIG_TYPE
163 # undef SIZEOF_NCBI_BIG
164 # define NCBI_BIG_TYPE double
165 # define SIZEOF_NCBI_BIG SIZEOF_DOUBLE
166 #endif
167 #if (SIZEOF_VOIDP > SIZEOF_NCBI_BIG)
168 # undef NCBI_BIG_TYPE
169 # undef SIZEOF_NCBI_BIG
170 # define NCBI_BIG_TYPE void*
171 # define SIZEOF_NCBI_BIG SIZEOF_VOIDP
172 #endif
173 
174 /**
175  * Define large scalar type.
176  *
177  * This is platform dependent. It could be an Int8, long double, double
178  * or void*.
179  */
181 
182 
183 #ifndef HAVE_INTPTR_T
184 # if SIZEOF_INT == SIZEOF_VOIDP
185 typedef int intptr_t;
186 # elif SIZEOF_LONG == SIZEOF_VOIDP
187 typedef long intptr_t;
188 # elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
189 typedef long long intptr_t;
190 # else
191 # error No integer type is the same size as a pointer!
192 # endif
193 #endif
194 
195 #ifndef HAVE_UINTPTR_T
196 # if SIZEOF_INT == SIZEOF_VOIDP
197 typedef unsigned int uintptr_t;
198 # elif SIZEOF_LONG == SIZEOF_VOIDP
199 typedef unsigned long uintptr_t;
200 # elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
201 typedef unsigned long long uintptr_t;
202 # else
203 # error No integer type is the same size as a pointer!
204 # endif
205 #endif
206 
207 
208 /* Macros for constant values definition
209  */
210 
211 #ifdef HAVE_INTTYPES_H
212 # define NCBI_CONST_INT8(v) INT64_C(v)
213 # define NCBI_CONST_UINT8(v) UINT64_C(v)
214 # define NCBI_INT8_FORMAT_SPEC PRId64
215 # define NCBI_UINT8_FORMAT_SPEC PRIu64
216 #elif (SIZEOF_LONG == 8)
217 # define NCBI_CONST_INT8(v) v##L
218 # define NCBI_CONST_UINT8(v) v##UL
219 # define NCBI_INT8_FORMAT_SPEC "ld"
220 # define NCBI_UINT8_FORMAT_SPEC "lu"
221 #elif (SIZEOF_LONG_LONG == 8)
222 # define NCBI_CONST_INT8(v) v##LL
223 # define NCBI_CONST_UINT8(v) v##ULL
224 # if defined(__MINGW32__) || defined(__MINGW64__)
225 # define NCBI_INT8_FORMAT_SPEC "I64d"
226 # define NCBI_UINT8_FORMAT_SPEC "I64u"
227 # else
228 # define NCBI_INT8_FORMAT_SPEC "lld"
229 # define NCBI_UINT8_FORMAT_SPEC "llu"
230 # endif
231 #elif defined(NCBI_USE_INT64)
232 # define NCBI_CONST_INT8(v) v##i64
233 # define NCBI_CONST_UINT8(v) v##ui64
234 # define NCBI_INT8_FORMAT_SPEC "I64d"
235 # define NCBI_UINT8_FORMAT_SPEC "I64u"
236 #else
237 # define NCBI_CONST_INT8(v) v
238 # define NCBI_CONST_UINT8(v) v
239 # define NCBI_INT8_FORMAT_SPEC "d"
240 # define NCBI_UINT8_FORMAT_SPEC "u"
241 #endif
242 #if (SIZEOF_LONG_DOUBLE > SIZEOF_DOUBLE)
243 # define NCBI_CONST_LONGDOUBLE(v) v##L
244 #else
245 # define NCBI_CONST_LONGDOUBLE(v) v
246 #endif
247 
248 
249 /* Undef auxiliaries
250  */
251 
252 #undef SIZEOF_NCBI_BIG
253 #undef NCBI_BIG_TYPE
254 #undef NCBI_INT8_TYPE
255 
256 
257 #endif /* CORELIB___NCBITYPE__H */
258 
259 
260 /* @} */
Uint8 uint64_t
Int4 int32_t
Int2 int16_t
Int8 int64_t
unsigned char uint8_t
Uint2 uint16_t
signed char int8_t
Uint4 uint32_t
int intptr_t
Definition: ncbitype.h:185
signed char Schar
Alias for signed char.
Definition: ncbitype.h:94
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
int16_t Int2
2-byte (16-bit) signed integer
Definition: ncbitype.h:100
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
unsigned char Uchar
Alias for unsigned char.
Definition: ncbitype.h:95
Int8 Ncbi_BigScalar
Define large scalar type.
Definition: ncbitype.h:180
unsigned int uintptr_t
Definition: ncbitype.h:197
char Char
Alias for char.
Definition: ncbitype.h:93
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
uint16_t Uint2
2-byte (16-bit) unsigned integer
Definition: ncbitype.h:101
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
int8_t Int1
1-byte (8-bit) signed integer
Definition: ncbitype.h:98
#define NCBI_BIG_TYPE
Definition: ncbitype.h:153
Front end for a platform-specific configuration summary.
Modified on Wed Sep 04 15:07:12 2024 by modify_doxy.py rev. 669887