5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2002 - 2006 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program 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.
20 /****h* silcutil/SILC Types
24 * This header includes the most basic types used in the SILC source
25 * tree, such as arithmetic types and their manipulation macros. This
26 * file is included in the silcincludes.h and is automatically available
34 /****d* silcutil/SILCTypes/TRUE
42 * Boolean true value indicator.
51 /****d* silcutil/SILCTypes/FALSE
59 * Boolean false value indicator.
68 /****d* silcutil/SILCTypes/SilcBool
72 * typedef unigned char SilcBool;
76 * Boolean value, and is always 8-bits. Represents value 0 or 1.
79 typedef unsigned char SilcBool;
81 /****d* silcutil/SILCTypes/bool
85 * #define SilcBool ...
89 * Boolean value, and is 8-bits. Represents value 0 or 1. In
90 * C++ code this type is defined by the C++, and this definition is
95 * This macro is deprecated. Use SilcBool instead.
105 #define bool unsigned char
110 #define silc_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
112 #if SILC_SIZEOF_SHORT > 2
113 #error "size of the short must be 2 bytes"
116 /****d* silcutil/SILCTypes/SilcUInt8
120 * typedef unsigned char SilcUInt8;
124 * 8-bit unsigned integer.
128 typedef unsigned char SilcUInt8;
131 /****d* silcutil/SILCTypes/SilcInt8
135 * typedef signed char SilcInt8;
139 * 8-bit signed integer.
143 typedef signed char SilcInt8;
146 /****d* silcutil/SILCTypes/SilcUInt16
150 * typedef unsigned short SilcUInt16;
154 * 16-bit unsigned integer. Guaranteed to be 16-bits.
158 typedef unsigned short SilcUInt16;
161 /****d* silcutil/SILCTypes/SilcInt16
165 * typedef signed short SilcInt16;
169 * 16-bit signed integer. Guaranteed to be 16-bits.
173 typedef signed short SilcInt16;
176 /****d* silcutil/SILCTypes/SilcUInt32
180 * typedef unsigned long SilcUInt32;
184 * 32-bit unsigned integer. Guaranteed to be 32-bits.
188 #if SILC_SIZEOF_LONG == 4
189 typedef unsigned long SilcUInt32;
190 typedef signed long SilcInt32;
192 #if SILC_SIZEOF_INT == 4
193 typedef unsigned int SilcUInt32;
194 typedef signed int SilcInt32;
196 #if SILC_SIZEOF_LONG_LONG >= 4
198 typedef unsigned long long SilcUInt32;
199 typedef signed long long SilcInt32;
206 /****d* silcutil/SILCTypes/SilcInt32
210 * typedef signed long SilcInt32;
214 * 32-bit signed integer. Guaranteed to be 32-bits.
218 /****d* silcutil/SILCTypes/SilcUInt64
222 * typedef unsigned long long SilcUInt64;
226 * 64-bit unsigned integer. Guaranteed to be 64-bits on systems that
231 #if SILC_SIZEOF_LONG >= 8
232 typedef unsigned long SilcUInt64;
233 typedef signed long SilcInt64;
235 #if SILC_SIZEOF_LONG_LONG >= 8
237 typedef unsigned long long SilcUInt64;
238 typedef signed long long SilcInt64;
240 typedef unsigned __int64 SilcUInt64;
241 typedef signed __int64 SilcInt64;
244 typedef SilcUInt32 SilcUInt64;
245 typedef SilcInt32 SilcInt64;
250 /****d* silcutil/SILCTypes/SilcInt64
254 * typedef signed long long SilcInt64;
258 * 64-bit signed integer. Guaranteed to be 64-bits on systems that
263 #if SILC_SIZEOF_VOID_P < 4
264 typedef SilcUInt32 * void *;
269 #define SILC_GET_WORD(cp) ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \
270 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16) \
271 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8) \
272 | ((SilcUInt32)(SilcUInt8)(cp)[3])
274 /****d* silcutil/SILCTypes/SILC_GET16_MSB
278 * #define SILC_GET16_MSB ...
282 * Return two 8-bit bytes, most significant bytes first.
286 #define SILC_GET16_MSB(l, cp) \
288 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0] << 8) \
289 | ((SilcUInt32)(SilcUInt8)(cp)[1]); \
293 /****d* silcutil/SILCTypes/SILC_GET32_MSB
297 * #define SILC_GET32_MSB ...
301 * Return four 8-bit bytes, most significant bytes first.
305 #define SILC_GET32_MSB(l, cp) \
307 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \
308 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16) \
309 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8) \
310 | ((SilcUInt32)(SilcUInt8)(cp)[3]); \
314 /****d* silcutil/SILCTypes/SILC_GET64_MSB
318 * #define SILC_GET64_MSB ...
322 * Return eight 8-bit bytes, most significant bytes first.
326 #define SILC_GET64_MSB(l, cp) \
328 (l) = ((((SilcUInt64)SILC_GET_WORD((cp))) << 32) | \
329 ((SilcUInt64)SILC_GET_WORD((cp) + 4))); \
333 /****d* silcutil/SILCTypes/SILC_GET16_LSB
337 * #define SILC_GET16_MSB ...
341 * Return two 8-bit bytes, least significant bytes first.
345 #define SILC_GET16_LSB(l, cp) \
347 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \
348 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8); \
352 /****d* silcutil/SILCTypes/SILC_GET32_LSB
356 * #define SILC_GET32_LSB ...
360 * Return four 8-bit bytes, least significant bytes first.
364 #define SILC_GET32_LSB(l, cp) \
366 (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \
367 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \
368 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \
369 | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24); \
372 /* Same as upper but XOR the result always. Special purpose macro. */
373 #define SILC_GET32_X_LSB(l, cp) \
374 (l) ^= ((SilcUInt32)(SilcUInt8)(cp)[0]) \
375 | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \
376 | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \
377 | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24)
380 /****d* silcutil/SILCTypes/SILC_PUT16_MSB
384 * #define SILC_PUT16_MSB ...
388 * Put two 8-bit bytes, most significant bytes first.
392 #define SILC_PUT16_MSB(l, cp) \
394 (cp)[0] = (SilcUInt8)((l) >> 8); \
395 (cp)[1] = (SilcUInt8)(l); \
399 /****d* silcutil/SILCTypes/SILC_PUT32_MSB
403 * #define SILC_PUT32_MSB ...
407 * Put four 8-bit bytes, most significant bytes first.
411 #define SILC_PUT32_MSB(l, cp) \
413 (cp)[0] = (SilcUInt8)((l) >> 24); \
414 (cp)[1] = (SilcUInt8)((l) >> 16); \
415 (cp)[2] = (SilcUInt8)((l) >> 8); \
416 (cp)[3] = (SilcUInt8)(l); \
420 /****d* silcutil/SILCTypes/SILC_PUT64_MSB
424 * #define SILC_PUT64_MSB ...
428 * Put eight 8-bit bytes, most significant bytes first.
432 #define SILC_PUT64_MSB(l, cp) \
434 SILC_PUT32_MSB((SilcUInt32)((SilcUInt64)(l) >> 32), (cp)); \
435 SILC_PUT32_MSB((SilcUInt32)(l), (cp) + 4); \
439 /****d* silcutil/SILCTypes/SILC_PUT16_LSB
443 * #define SILC_PUT16_LSB ...
447 * Put two 8-bit bytes, least significant bytes first.
451 #define SILC_PUT16_LSB(l, cp) \
453 (cp)[0] = (SilcUInt8)(l); \
454 (cp)[1] = (SilcUInt8)((l) >> 8); \
458 /****d* silcutil/SILCTypes/SILC_PUT32_LSB
462 * #define SILC_PUT32_LSB ...
466 * Put four 8-bit bytes, least significant bytes first.
470 #define SILC_PUT32_LSB(l, cp) \
472 (cp)[0] = (SilcUInt8)(l); \
473 (cp)[1] = (SilcUInt8)((l) >> 8); \
474 (cp)[2] = (SilcUInt8)((l) >> 16); \
475 (cp)[3] = (SilcUInt8)((l) >> 24); \
479 /****d* silcutil/SILCTypes/SILC_SWAB_16
483 * #define SILC_SWAB_16 ...
487 * Swabs 16-bit unsigned integer byte order.
491 #define SILC_SWAB_16(l) \
492 ((SilcUInt16)(((SilcUInt16)(l) & (SilcUInt16)0x00FFU) << 8) | \
493 (((SilcUInt16)(l) & (SilcUInt16)0xFF00U) >> 8))
496 /****d* silcutil/SILCTypes/SILC_SWAB_32
500 * #define SILC_SWAB_32 ...
504 * Swabs 32-bit unsigned integer byte order.
508 #define SILC_SWAB_32(l) \
509 ((SilcUInt32)(((SilcUInt32)(l) & (SilcUInt32)0x000000FFUL) << 24) | \
510 (((SilcUInt32)(l) & (SilcUInt32)0x0000FF00UL) << 8) | \
511 (((SilcUInt32)(l) & (SilcUInt32)0x00FF0000UL) >> 8) | \
512 (((SilcUInt32)(l) & (SilcUInt32)0xFF000000UL) >> 24))
515 /****d* silcutil/SILCTypes/SILC_PTR_TO_32
519 * #define SILC_PTR_TO_32 ...
523 * Type casts a pointer's value into a 32-bit integer. Use this to
524 * avoid compiler warnings when type casting pointers to integers
529 #if SILC_SIZEOF_VOID_P < 8
530 #define SILC_PTR_TO_32(_ptr__) ((SilcUInt32)(_ptr__))
532 #define SILC_PTR_TO_32(_ptr__) \
533 ((SilcUInt32)((SilcUInt64)(_ptr__) & (SilcUInt32)0xFFFFFFFFUL))
537 /****d* silcutil/SILCTypes/SILC_PTR_TO_64
541 * #define SILC_PTR_TO_64 ...
545 * Type casts a pointer's value into a 64-bit integer. Use this to
546 * avoid compiler warnings when type casting pointers to integers
551 #if SILC_SIZEOF_VOID_P < 8
552 #define SILC_PTR_TO_64(_ptr__) ((SilcUInt64)((SilcUInt32)(_ptr__)))
554 #define SILC_PTR_TO_64(_ptr__) \
555 ((SilcUInt64)((SilcUInt64)(_ptr__) & (SilcUInt32)0xFFFFFFFFUL))
559 /****d* silcutil/SILCTypes/SILC_32_TO_PTR
563 * #define SILC_PTR_TO_32 ...
567 * Type casts a 32-bit integer value into a pointer. Use this to
568 * avoid compiler warnings when type casting integers to pointers of
573 #if SILC_SIZEOF_VOID_P < 8
574 #define SILC_32_TO_PTR(_ival__) ((void *)((SilcUInt32)(_ival__)))
576 #define SILC_32_TO_PTR(_ival__) ((void *)((SilcUInt64)(_ival__)))
580 /****d* silcutil/SILCTypes/SILC_64_TO_PTR
584 * #define SILC_PTR_TO_64 ...
588 * Type casts a 64-bit integer value into a pointer. Use this to
589 * avoid compiler warnings when type casting integers to pointers of
594 #if SILC_SIZEOF_VOID_P < 8
595 #define SILC_64_TO_PTR(_ival__) \
596 ((void *)((SilcUInt32)((SilcUInt64)(_ival__) & (SilcUInt32)0xFFFFFFFFUL)))
598 #define SILC_64_TO_PTR(_ival__) ((void *)((SilcUInt64)(_ival__)))
602 #endif /* SILCTYPES_H */