IBR-DTNSuite
0.8
|
00001 /* 00002 --------------------------------------------------------------------------- 00003 Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved. 00004 00005 LICENSE TERMS 00006 00007 The free distribution and use of this software in both source and binary 00008 form is allowed (with or without changes) provided that: 00009 00010 1. distributions of this source code include the above copyright 00011 notice, this list of conditions and the following disclaimer; 00012 00013 2. distributions in binary form include the above copyright 00014 notice, this list of conditions and the following disclaimer 00015 in the documentation and/or other associated materials; 00016 00017 3. the copyright holder's name is not used to endorse products 00018 built using this software without specific written permission. 00019 00020 ALTERNATIVELY, provided that this notice is retained in full, this product 00021 may be distributed under the terms of the GNU General Public License (GPL), 00022 in which case the provisions of the GPL apply INSTEAD OF those given above. 00023 00024 DISCLAIMER 00025 00026 This software is provided 'as is' with no explicit or implied warranties 00027 in respect of its properties, including, but not limited to, correctness 00028 and/or fitness for purpose. 00029 --------------------------------------------------------------------------- 00030 Issue 09/09/2006 00031 00032 The unsigned integer types defined here are of the form uint_<nn>t where 00033 <nn> is the length of the type; for example, the unsigned 32-bit type is 00034 'uint_32t'. These are NOT the same as the 'C99 integer types' that are 00035 defined in the inttypes.h and stdint.h headers since attempts to use these 00036 types have shown that support for them is still highly variable. However, 00037 since the latter are of the form uint<nn>_t, a regular expression search 00038 and replace (in VC++ search on 'uint_{:z}t' and replace with 'uint\1_t') 00039 can be used to convert the types used here to the C99 standard types. 00040 */ 00041 00042 #ifndef BRG_TYPES_H 00043 #define BRG_TYPES_H 00044 00045 #if defined(__cplusplus) 00046 extern "C" { 00047 #endif 00048 00049 #include <limits.h> 00050 00051 #ifndef BRG_UI8 00052 # define BRG_UI8 00053 # if UCHAR_MAX == 255u 00054 typedef unsigned char uint_8t; 00055 # else 00056 # error Please define uint_8t as an 8-bit unsigned integer type in brg_types.h 00057 # endif 00058 #endif 00059 00060 #ifndef BRG_UI16 00061 # define BRG_UI16 00062 # if USHRT_MAX == 65535u 00063 typedef unsigned short uint_16t; 00064 # else 00065 # error Please define uint_16t as a 16-bit unsigned short type in brg_types.h 00066 # endif 00067 #endif 00068 00069 #ifndef BRG_UI32 00070 # define BRG_UI32 00071 # if UINT_MAX == 4294967295u 00072 # define li_32(h) 0x##h##u 00073 typedef unsigned int uint_32t; 00074 # elif ULONG_MAX == 4294967295u 00075 # define li_32(h) 0x##h##ul 00076 typedef unsigned long uint_32t; 00077 # elif defined( _CRAY ) 00078 # error This code needs 32-bit data types, which Cray machines do not provide 00079 # else 00080 # error Please define uint_32t as a 32-bit unsigned integer type in brg_types.h 00081 # endif 00082 #endif 00083 00084 #ifndef BRG_UI64 00085 # if defined( __BORLANDC__ ) && !defined( __MSDOS__ ) 00086 # define BRG_UI64 00087 # define li_64(h) 0x##h##ull 00088 typedef unsigned __int64 uint_64t; 00089 # elif defined( _MSC_VER ) && ( _MSC_VER < 1300 ) /* 1300 == VC++ 7.0 */ 00090 # define BRG_UI64 00091 # define li_64(h) 0x##h##ui64 00092 typedef unsigned __int64 uint_64t; 00093 # elif defined( __sun ) && defined(ULONG_MAX) && ULONG_MAX == 0xfffffffful 00094 # define BRG_UI64 00095 # define li_64(h) 0x##h##ull 00096 typedef unsigned long long uint_64t; 00097 # elif defined( __MVS__ ) 00098 # define li_64(h) 0x##h##ull 00099 typedef unsigned int long long uint_64t; 00100 # elif defined( UINT_MAX ) && UINT_MAX > 4294967295u 00101 # if UINT_MAX == 18446744073709551615u 00102 # define BRG_UI64 00103 # define li_64(h) 0x##h##u 00104 typedef unsigned int uint_64t; 00105 # endif 00106 # elif defined( ULONG_MAX ) && ULONG_MAX > 4294967295u 00107 # if ULONG_MAX == 18446744073709551615ul 00108 # define BRG_UI64 00109 # define li_64(h) 0x##h##ul 00110 typedef unsigned long uint_64t; 00111 # endif 00112 # elif defined( ULLONG_MAX ) && ULLONG_MAX > 4294967295u 00113 # if ULLONG_MAX == 18446744073709551615ull 00114 # define BRG_UI64 00115 # define li_64(h) 0x##h##ull 00116 typedef unsigned long long uint_64t; 00117 # endif 00118 # elif defined( ULONG_LONG_MAX ) && ULONG_LONG_MAX > 4294967295u 00119 # if ULONG_LONG_MAX == 18446744073709551615ull 00120 # define BRG_UI64 00121 # define li_64(h) 0x##h##ull 00122 typedef unsigned long long uint_64t; 00123 # endif 00124 # endif 00125 #endif 00126 00127 #if defined( NEED_UINT_64T ) && !defined( BRG_UI64 ) 00128 # error Please define uint_64t as an unsigned 64 bit type in brg_types.h 00129 #endif 00130 00131 #ifndef RETURN_VALUES 00132 # define RETURN_VALUES 00133 # if defined( DLL_EXPORT ) 00134 # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 00135 # define VOID_RETURN __declspec( dllexport ) void __stdcall 00136 # define INT_RETURN __declspec( dllexport ) int __stdcall 00137 # elif defined( __GNUC__ ) 00138 # define VOID_RETURN __declspec( __dllexport__ ) void 00139 # define INT_RETURN __declspec( __dllexport__ ) int 00140 # else 00141 # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 00142 # endif 00143 # elif defined( DLL_IMPORT ) 00144 # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 00145 # define VOID_RETURN __declspec( dllimport ) void __stdcall 00146 # define INT_RETURN __declspec( dllimport ) int __stdcall 00147 # elif defined( __GNUC__ ) 00148 # define VOID_RETURN __declspec( __dllimport__ ) void 00149 # define INT_RETURN __declspec( __dllimport__ ) int 00150 # else 00151 # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 00152 # endif 00153 # elif defined( __WATCOMC__ ) 00154 # define VOID_RETURN void __cdecl 00155 # define INT_RETURN int __cdecl 00156 # else 00157 # define VOID_RETURN void 00158 # define INT_RETURN int 00159 # endif 00160 #endif 00161 00162 /* These defines are used to declare buffers in a way that allows 00163 faster operations on longer variables to be used. In all these 00164 defines 'size' must be a power of 2 and >= 8 00165 00166 dec_unit_type(size,x) declares a variable 'x' of length 00167 'size' bits 00168 00169 dec_bufr_type(size,bsize,x) declares a buffer 'x' of length 'bsize' 00170 bytes defined as an array of variables 00171 each of 'size' bits (bsize must be a 00172 multiple of size / 8) 00173 00174 ptr_cast(x,size) casts a pointer to a pointer to a 00175 varaiable of length 'size' bits 00176 */ 00177 00178 #define ui_type(size) uint_##size##t 00179 #define dec_unit_type(size,x) typedef ui_type(size) x 00180 #define dec_bufr_type(size,bsize,x) typedef ui_type(size) x[bsize / (size >> 3)] 00181 #define unit_cast(size,x) ((ui_type(size) )(x)) 00182 #define ptr_cast(x,size) ((ui_type(size)*)(x)) 00183 00184 #if defined(__cplusplus) 00185 } 00186 #endif 00187 00188 #endif