IBR-DTNSuite  0.10
brg_types.h
Go to the documentation of this file.
1 /*
2  ---------------------------------------------------------------------------
3  Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.
4 
5  LICENSE TERMS
6 
7  The free distribution and use of this software in both source and binary
8  form is allowed (with or without changes) provided that:
9 
10  1. distributions of this source code include the above copyright
11  notice, this list of conditions and the following disclaimer;
12 
13  2. distributions in binary form include the above copyright
14  notice, this list of conditions and the following disclaimer
15  in the documentation and/or other associated materials;
16 
17  3. the copyright holder's name is not used to endorse products
18  built using this software without specific written permission.
19 
20  ALTERNATIVELY, provided that this notice is retained in full, this product
21  may be distributed under the terms of the GNU General Public License (GPL),
22  in which case the provisions of the GPL apply INSTEAD OF those given above.
23 
24  DISCLAIMER
25 
26  This software is provided 'as is' with no explicit or implied warranties
27  in respect of its properties, including, but not limited to, correctness
28  and/or fitness for purpose.
29  ---------------------------------------------------------------------------
30  Issue 09/09/2006
31 
32  The unsigned integer types defined here are of the form uint_<nn>t where
33  <nn> is the length of the type; for example, the unsigned 32-bit type is
34  'uint_32t'. These are NOT the same as the 'C99 integer types' that are
35  defined in the inttypes.h and stdint.h headers since attempts to use these
36  types have shown that support for them is still highly variable. However,
37  since the latter are of the form uint<nn>_t, a regular expression search
38  and replace (in VC++ search on 'uint_{:z}t' and replace with 'uint\1_t')
39  can be used to convert the types used here to the C99 standard types.
40 */
41 
42 #ifndef BRG_TYPES_H
43 #define BRG_TYPES_H
44 
45 #if defined(__cplusplus)
46 extern "C" {
47 #endif
48 
49 #include <limits.h>
50 
51 #ifndef BRG_UI8
52 # define BRG_UI8
53 # if UCHAR_MAX == 255u
54  typedef unsigned char uint_8t;
55 # else
56 # error Please define uint_8t as an 8-bit unsigned integer type in brg_types.h
57 # endif
58 #endif
59 
60 #ifndef BRG_UI16
61 # define BRG_UI16
62 # if USHRT_MAX == 65535u
63  typedef unsigned short uint_16t;
64 # else
65 # error Please define uint_16t as a 16-bit unsigned short type in brg_types.h
66 # endif
67 #endif
68 
69 #ifndef BRG_UI32
70 # define BRG_UI32
71 # if UINT_MAX == 4294967295u
72 # define li_32(h) 0x##h##u
73  typedef unsigned int uint_32t;
74 # elif ULONG_MAX == 4294967295u
75 # define li_32(h) 0x##h##ul
76  typedef unsigned long uint_32t;
77 # elif defined( _CRAY )
78 # error This code needs 32-bit data types, which Cray machines do not provide
79 # else
80 # error Please define uint_32t as a 32-bit unsigned integer type in brg_types.h
81 # endif
82 #endif
83 
84 #ifndef BRG_UI64
85 # if defined( __BORLANDC__ ) && !defined( __MSDOS__ )
86 # define BRG_UI64
87 # define li_64(h) 0x##h##ull
88  typedef unsigned __int64 uint_64t;
89 # elif defined( _MSC_VER ) && ( _MSC_VER < 1300 ) /* 1300 == VC++ 7.0 */
90 # define BRG_UI64
91 # define li_64(h) 0x##h##ui64
92  typedef unsigned __int64 uint_64t;
93 # elif defined( __sun ) && defined(ULONG_MAX) && ULONG_MAX == 0xfffffffful
94 # define BRG_UI64
95 # define li_64(h) 0x##h##ull
96  typedef unsigned long long uint_64t;
97 # elif defined( __MVS__ )
98 # define li_64(h) 0x##h##ull
99  typedef unsigned int long long uint_64t;
100 # elif defined( UINT_MAX ) && UINT_MAX > 4294967295u
101 # if UINT_MAX == 18446744073709551615u
102 # define BRG_UI64
103 # define li_64(h) 0x##h##u
104  typedef unsigned int uint_64t;
105 # endif
106 # elif defined( ULONG_MAX ) && ULONG_MAX > 4294967295u
107 # if ULONG_MAX == 18446744073709551615ul
108 # define BRG_UI64
109 # define li_64(h) 0x##h##ul
110  typedef unsigned long uint_64t;
111 # endif
112 # elif defined( ULLONG_MAX ) && ULLONG_MAX > 4294967295u
113 # if ULLONG_MAX == 18446744073709551615ull
114 # define BRG_UI64
115 # define li_64(h) 0x##h##ull
116  typedef unsigned long long uint_64t;
117 # endif
118 # elif defined( ULONG_LONG_MAX ) && ULONG_LONG_MAX > 4294967295u
119 # if ULONG_LONG_MAX == 18446744073709551615ull
120 # define BRG_UI64
121 # define li_64(h) 0x##h##ull
122  typedef unsigned long long uint_64t;
123 # endif
124 # endif
125 #endif
126 
127 #if defined( NEED_UINT_64T ) && !defined( BRG_UI64 )
128 # error Please define uint_64t as an unsigned 64 bit type in brg_types.h
129 #endif
130 
131 #ifndef RETURN_VALUES
132 # define RETURN_VALUES
133 # if defined( DLL_EXPORT )
134 # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )
135 # define VOID_RETURN __declspec( dllexport ) void __stdcall
136 # define INT_RETURN __declspec( dllexport ) int __stdcall
137 # elif defined( __GNUC__ )
138 # define VOID_RETURN __declspec( __dllexport__ ) void
139 # define INT_RETURN __declspec( __dllexport__ ) int
140 # else
141 # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers
142 # endif
143 # elif defined( DLL_IMPORT )
144 # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )
145 # define VOID_RETURN __declspec( dllimport ) void __stdcall
146 # define INT_RETURN __declspec( dllimport ) int __stdcall
147 # elif defined( __GNUC__ )
148 # define VOID_RETURN __declspec( __dllimport__ ) void
149 # define INT_RETURN __declspec( __dllimport__ ) int
150 # else
151 # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers
152 # endif
153 # elif defined( __WATCOMC__ )
154 # define VOID_RETURN void __cdecl
155 # define INT_RETURN int __cdecl
156 # else
157 # define VOID_RETURN void
158 # define INT_RETURN int
159 # endif
160 #endif
161 
162 /* These defines are used to declare buffers in a way that allows
163  faster operations on longer variables to be used. In all these
164  defines 'size' must be a power of 2 and >= 8
165 
166  dec_unit_type(size,x) declares a variable 'x' of length
167  'size' bits
168 
169  dec_bufr_type(size,bsize,x) declares a buffer 'x' of length 'bsize'
170  bytes defined as an array of variables
171  each of 'size' bits (bsize must be a
172  multiple of size / 8)
173 
174  ptr_cast(x,size) casts a pointer to a pointer to a
175  varaiable of length 'size' bits
176 */
177 
178 #define ui_type(size) uint_##size##t
179 #define dec_unit_type(size,x) typedef ui_type(size) x
180 #define dec_bufr_type(size,bsize,x) typedef ui_type(size) x[bsize / (size >> 3)]
181 #define unit_cast(size,x) ((ui_type(size) )(x))
182 #define ptr_cast(x,size) ((ui_type(size)*)(x))
183 
184 #if defined(__cplusplus)
185 }
186 #endif
187 
188 #endif