1 /* ucl_ptr.h -- low-level pointer constructs
3 This file is part of the UCL data compression library.
5 Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
8 The UCL library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 The UCL library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the UCL library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
28 /* WARNING: this file should *not* be used by applications. It is
29 part of the implementation of the library and is subject
42 /* This is the lowest part of the UCL library.
43 * It deals with pointer representations at bit level.
47 /***********************************************************************
49 ************************************************************************/
51 #if defined(__UCL_DOS16) || defined(__UCL_WIN16)
53 # if 1 && defined(__WATCOMC__)
55 __UCL_EXTERN_C
unsigned char _HShift
;
56 # define __UCL_HShift _HShift
57 # elif 1 && defined(_MSC_VER)
58 __UCL_EXTERN_C
unsigned short __near _AHSHIFT
;
59 # define __UCL_HShift ((unsigned) &_AHSHIFT)
60 # elif defined(__UCL_WIN16)
61 # define __UCL_HShift 3
63 # define __UCL_HShift 12
65 # if !defined(_FP_SEG) && defined(FP_SEG)
66 # define _FP_SEG FP_SEG
68 # if !defined(_FP_OFF) && defined(FP_OFF)
69 # define _FP_OFF FP_OFF
74 /***********************************************************************
76 ************************************************************************/
79 #if !defined(ucl_ptrdiff_t)
80 #if (UINT_MAX >= UCL_0xffffffffL)
81 typedef ptrdiff_t ucl_ptrdiff_t
;
83 typedef long ucl_ptrdiff_t
;
88 /* Unsigned type that has *exactly* the same number of bits as a ucl_voidp */
89 #if !defined(__UCL_HAVE_PTR_T)
90 # if defined(ucl_ptr_t)
91 # define __UCL_HAVE_PTR_T
94 #if !defined(__UCL_HAVE_PTR_T)
95 # if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_LONG)
96 # if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_LONG)
97 typedef unsigned long ucl_ptr_t
;
98 typedef long ucl_sptr_t
;
99 # define __UCL_HAVE_PTR_T
103 #if !defined(__UCL_HAVE_PTR_T)
104 # if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED)
105 # if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED)
106 typedef unsigned int ucl_ptr_t
;
107 typedef int ucl_sptr_t
;
108 # define __UCL_HAVE_PTR_T
112 #if !defined(__UCL_HAVE_PTR_T)
113 # if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_SHORT)
114 # if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_SHORT)
115 typedef unsigned short ucl_ptr_t
;
116 typedef short ucl_sptr_t
;
117 # define __UCL_HAVE_PTR_T
121 #if !defined(__UCL_HAVE_PTR_T)
122 # if defined(UCL_HAVE_CONFIG_H) || defined(SIZEOF_CHAR_P)
123 # error "no suitable type for ucl_ptr_t"
125 typedef unsigned long ucl_ptr_t
;
126 typedef long ucl_sptr_t
;
127 # define __UCL_HAVE_PTR_T
132 /***********************************************************************
134 ************************************************************************/
136 /* Always use the safe (=integral) version for pointer-comparisions.
137 * The compiler should optimize away the additional casts anyway.
139 * Note that this only works if the representation and ordering
140 * of the pointer and the integral is the same (at bit level).
142 * Most 16-bit compilers have their own view about pointers -
143 * fortunately they don't care about comparing pointers
144 * that are pointing to Nirvana.
147 #if defined(__UCL_DOS16) || defined(__UCL_WIN16)
148 #define PTR(a) ((ucl_bytep) (a))
149 /* only need the low bits of the pointer -> offset is ok */
150 #define PTR_ALIGNED_4(a) ((_FP_OFF(a) & 3) == 0)
151 #define PTR_ALIGNED2_4(a,b) (((_FP_OFF(a) | _FP_OFF(b)) & 3) == 0)
153 #define PTR(a) ((ucl_ptr_t) (a))
154 #define PTR_LINEAR(a) PTR(a)
155 #define PTR_ALIGNED_4(a) ((PTR_LINEAR(a) & 3) == 0)
156 #define PTR_ALIGNED_8(a) ((PTR_LINEAR(a) & 7) == 0)
157 #define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0)
158 #define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0)
161 #define PTR_LT(a,b) (PTR(a) < PTR(b))
162 #define PTR_GE(a,b) (PTR(a) >= PTR(b))
163 #define PTR_DIFF(a,b) ((ucl_ptrdiff_t) (PTR(a) - PTR(b)))
166 UCL_EXTERN(ucl_ptr_t
)
167 __ucl_ptr_linear(const ucl_voidp ptr
);
173 unsigned char a_uchar
;
175 unsigned short a_ushort
;
179 unsigned long a_ulong
;
182 ucl_int32 a_ucl_int32
;
183 ucl_uint32 a_ucl_uint32
;
184 ptrdiff_t a_ptrdiff_t
;
185 ucl_ptrdiff_t a_ucl_ptrdiff_t
;
186 ucl_ptr_t a_ucl_ptr_t
;
187 ucl_voidp a_ucl_voidp
;
189 ucl_bytep a_ucl_bytep
;
190 ucl_bytepp a_ucl_bytepp
;
191 ucl_uintp a_ucl_uintp
;
192 ucl_uint
* a_ucl_uint_p
;
193 ucl_uint32p a_ucl_uint32p
;
194 ucl_uint32
* a_ucl_uint32_p
;
195 unsigned char * a_uchar_p
;
206 #endif /* already included */