2 ---------------------------------------------------------------------------
\r
3 Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
\r
7 The redistribution and use of this software (with or without changes)
\r
8 is allowed without the payment of fees or royalties provided that:
\r
10 1. source code distributions include the above copyright notice, this
\r
11 list of conditions and the following disclaimer;
\r
13 2. binary distributions include the above copyright notice, this list
\r
14 of conditions and the following disclaimer in their documentation;
\r
16 3. the name of the copyright holder is not used to endorse products
\r
17 built using this software without specific written permission.
\r
21 This software is provided 'as is' with no explicit or implied warranties
\r
22 in respect of its properties, including, but not limited to, correctness
\r
23 and/or fitness for purpose.
\r
24 ---------------------------------------------------------------------------
\r
25 Issue Date: 20/12/2007
\r
27 The unsigned integer types defined here are of the form uint_<nn>t where
\r
28 <nn> is the length of the type; for example, the unsigned 32-bit type is
\r
29 'uint_32t'. These are NOT the same as the 'C99 integer types' that are
\r
30 defined in the inttypes.h and stdint.h headers since attempts to use these
\r
31 types have shown that support for them is still highly variable. However,
\r
32 since the latter are of the form uint<nn>_t, a regular expression search
\r
33 and replace (in VC++ search on 'uint_{:z}t' and replace with 'uint\1_t')
\r
34 can be used to convert the types used here to the C99 standard types.
\r
37 #ifndef _BRG_TYPES_H
\r
38 #define _BRG_TYPES_H
\r
40 #if defined(__cplusplus)
\r
46 #if defined( _MSC_VER ) && ( _MSC_VER >= 1300 )
\r
47 # include <stddef.h>
\r
48 # define ptrint_t intptr_t
\r
49 #elif defined( __GNUC__ ) && ( __GNUC__ >= 3 )
\r
50 # include <stdint.h>
\r
51 # define ptrint_t intptr_t
\r
53 # define ptrint_t int
\r
58 # if UCHAR_MAX == 255u
\r
59 typedef unsigned char uint_8t;
\r
61 # error Please define uint_8t as an 8-bit unsigned integer type in brg_types.h
\r
67 # if USHRT_MAX == 65535u
\r
68 typedef unsigned short uint_16t;
\r
70 # error Please define uint_16t as a 16-bit unsigned short type in brg_types.h
\r
76 # if UINT_MAX == 4294967295u
\r
77 # define li_32(h) 0x##h##u
\r
78 typedef unsigned int uint_32t;
\r
79 # elif ULONG_MAX == 4294967295u
\r
80 # define li_32(h) 0x##h##ul
\r
81 typedef unsigned long uint_32t;
\r
82 # elif defined( _CRAY )
\r
83 # error This code needs 32-bit data types, which Cray machines do not provide
\r
85 # error Please define uint_32t as a 32-bit unsigned integer type in brg_types.h
\r
90 # if defined( __BORLANDC__ ) && !defined( __MSDOS__ )
\r
92 # define li_64(h) 0x##h##ui64
\r
93 typedef unsigned __int64 uint_64t;
\r
94 # elif defined( _MSC_VER ) && ( _MSC_VER < 1300 ) /* 1300 == VC++ 7.0 */
\r
96 # define li_64(h) 0x##h##ui64
\r
97 typedef unsigned __int64 uint_64t;
\r
98 # elif defined( __sun ) && defined( ULONG_MAX ) && ULONG_MAX == 0xfffffffful
\r
100 # define li_64(h) 0x##h##ull
\r
101 typedef unsigned long long uint_64t;
\r
102 # elif defined( __MVS__ )
\r
104 # define li_64(h) 0x##h##ull
\r
105 typedef unsigned int long long uint_64t;
\r
106 # elif defined( UINT_MAX ) && UINT_MAX > 4294967295u
\r
107 # if UINT_MAX == 18446744073709551615u
\r
109 # define li_64(h) 0x##h##u
\r
110 typedef unsigned int uint_64t;
\r
112 # elif defined( ULONG_MAX ) && ULONG_MAX > 4294967295u
\r
113 # if ULONG_MAX == 18446744073709551615ul
\r
115 # define li_64(h) 0x##h##ul
\r
116 typedef unsigned long uint_64t;
\r
118 # elif defined( ULLONG_MAX ) && ULLONG_MAX > 4294967295u
\r
119 # if ULLONG_MAX == 18446744073709551615ull
\r
121 # define li_64(h) 0x##h##ull
\r
122 typedef unsigned long long uint_64t;
\r
124 # elif defined( ULONG_LONG_MAX ) && ULONG_LONG_MAX > 4294967295u
\r
125 # if ULONG_LONG_MAX == 18446744073709551615ull
\r
127 # define li_64(h) 0x##h##ull
\r
128 typedef unsigned long long uint_64t;
\r
133 #if !defined( BRG_UI64 )
\r
134 # if defined( NEED_UINT_64T )
\r
135 # error Please define uint_64t as an unsigned 64 bit type in brg_types.h
\r
139 #ifndef RETURN_VALUES
\r
140 # define RETURN_VALUES
\r
141 # if defined( DLL_EXPORT )
\r
142 # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )
\r
143 # define VOID_RETURN __declspec( dllexport ) void __stdcall
\r
144 # define INT_RETURN __declspec( dllexport ) int __stdcall
\r
145 # elif defined( __GNUC__ )
\r
146 # define VOID_RETURN __declspec( __dllexport__ ) void
\r
147 # define INT_RETURN __declspec( __dllexport__ ) int
\r
149 # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers
\r
151 # elif defined( DLL_IMPORT )
\r
152 # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )
\r
153 # define VOID_RETURN __declspec( dllimport ) void __stdcall
\r
154 # define INT_RETURN __declspec( dllimport ) int __stdcall
\r
155 # elif defined( __GNUC__ )
\r
156 # define VOID_RETURN __declspec( __dllimport__ ) void
\r
157 # define INT_RETURN __declspec( __dllimport__ ) int
\r
159 # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers
\r
161 # elif defined( __WATCOMC__ )
\r
162 # define VOID_RETURN void __cdecl
\r
163 # define INT_RETURN int __cdecl
\r
165 # define VOID_RETURN void
\r
166 # define INT_RETURN int
\r
170 /* These defines are used to detect and set the memory alignment of pointers.
\r
171 Note that offsets are in bytes.
\r
173 ALIGN_OFFSET(x,n) return the positive or zero offset of
\r
174 the memory addressed by the pointer 'x'
\r
175 from an address that is aligned on an
\r
176 'n' byte boundary ('n' is a power of 2)
\r
178 ALIGN_FLOOR(x,n) return a pointer that points to memory
\r
179 that is aligned on an 'n' byte boundary
\r
180 and is not higher than the memory address
\r
181 pointed to by 'x' ('n' is a power of 2)
\r
183 ALIGN_CEIL(x,n) return a pointer that points to memory
\r
184 that is aligned on an 'n' byte boundary
\r
185 and is not lower than the memory address
\r
186 pointed to by 'x' ('n' is a power of 2)
\r
189 #define ALIGN_OFFSET(x,n) (((ptrint_t)(x)) & ((n) - 1))
\r
190 #define ALIGN_FLOOR(x,n) ((uint_8t*)(x) - ( ((ptrint_t)(x)) & ((n) - 1)))
\r
191 #define ALIGN_CEIL(x,n) ((uint_8t*)(x) + (-((ptrint_t)(x)) & ((n) - 1)))
\r
193 /* These defines are used to declare buffers in a way that allows
\r
194 faster operations on longer variables to be used. In all these
\r
195 defines 'size' must be a power of 2 and >= 8. NOTE that the
\r
196 buffer size is in bytes but the type length is in bits
\r
198 UNIT_TYPEDEF(x,size) declares a variable 'x' of length
\r
201 BUFR_TYPEDEF(x,size,bsize) declares a buffer 'x' of length 'bsize'
\r
202 bytes defined as an array of variables
\r
203 each of 'size' bits (bsize must be a
\r
204 multiple of size / 8)
\r
206 UNIT_CAST(x,size) casts a variable to a type of
\r
209 UPTR_CAST(x,size) casts a pointer to a pointer to a
\r
210 varaiable of length 'size' bits
\r
213 #define UI_TYPE(size) uint_##size##t
\r
214 #define UNIT_TYPEDEF(x,size) typedef UI_TYPE(size) x
\r
215 #define BUFR_TYPEDEF(x,size,bsize) typedef UI_TYPE(size) x[bsize / (size >> 3)]
\r
216 #define UNIT_CAST(x,size) ((UI_TYPE(size) )(x))
\r
217 #define UPTR_CAST(x,size) ((UI_TYPE(size)*)(x))
\r
219 #if defined(__cplusplus)
\r