Imported Upstream version 2.74.3
[platform/upstream/glib.git] / glib / gtypes.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 /*
21  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/.
25  */
26
27 #ifndef __G_TYPES_H__
28 #define __G_TYPES_H__
29
30 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
31 #error "Only <glib.h> can be included directly."
32 #endif
33
34 #include <glibconfig.h>
35 #include <glib/gmacros.h>
36 #include <glib/gversionmacros.h>
37 #include <time.h>
38
39 G_BEGIN_DECLS
40
41 /* Provide type definitions for commonly used types.
42  *  These are useful because a "gint8" can be adjusted
43  *  to be 1 byte (8 bits) on all platforms. Similarly and
44  *  more importantly, "gint32" can be adjusted to be
45  *  4 bytes (32 bits) on all platforms.
46  */
47
48 typedef char   gchar;
49 typedef short  gshort;
50 typedef long   glong;
51 typedef int    gint;
52 typedef gint   gboolean;
53
54 typedef unsigned char   guchar;
55 typedef unsigned short  gushort;
56 typedef unsigned long   gulong;
57 typedef unsigned int    guint;
58
59 typedef float   gfloat;
60 typedef double  gdouble;
61
62 /* Define min and max constants for the fixed size numerical types */
63 /**
64  * G_MININT8: (value -128)
65  *
66  * The minimum value which can be held in a #gint8.
67  *
68  * Since: 2.4
69  */
70 #define G_MININT8       ((gint8) (-G_MAXINT8 - 1))
71 #define G_MAXINT8       ((gint8)  0x7f)
72 #define G_MAXUINT8      ((guint8) 0xff)
73
74 /**
75  * G_MININT16: (value -32768)
76  *
77  * The minimum value which can be held in a #gint16.
78  *
79  * Since: 2.4
80  */
81 #define G_MININT16      ((gint16) (-G_MAXINT16 - 1))
82 #define G_MAXINT16      ((gint16)  0x7fff)
83 #define G_MAXUINT16     ((guint16) 0xffff)
84
85 /**
86  * G_MININT32: (value -2147483648)
87  *
88  * The minimum value which can be held in a #gint32.
89  *
90  * Since: 2.4
91  */
92 #define G_MININT32      ((gint32) (-G_MAXINT32 - 1))
93 #define G_MAXINT32      ((gint32)  0x7fffffff)
94 #define G_MAXUINT32     ((guint32) 0xffffffff)
95
96 /**
97  * G_MININT64: (value -9223372036854775808)
98  *
99  * The minimum value which can be held in a #gint64.
100  */
101 #define G_MININT64      ((gint64) (-G_MAXINT64 - G_GINT64_CONSTANT(1)))
102 #define G_MAXINT64      G_GINT64_CONSTANT(0x7fffffffffffffff)
103 #define G_MAXUINT64     G_GUINT64_CONSTANT(0xffffffffffffffff)
104
105 typedef void* gpointer;
106 typedef const void *gconstpointer;
107
108 typedef gint            (*GCompareFunc)         (gconstpointer  a,
109                                                  gconstpointer  b);
110 typedef gint            (*GCompareDataFunc)     (gconstpointer  a,
111                                                  gconstpointer  b,
112                                                  gpointer       user_data);
113 typedef gboolean        (*GEqualFunc)           (gconstpointer  a,
114                                                  gconstpointer  b);
115
116 /**
117  * GEqualFuncFull:
118  * @a: a value
119  * @b: a value to compare with
120  * @user_data: user data provided by the caller
121  *
122  * Specifies the type of a function used to test two values for
123  * equality. The function should return %TRUE if both values are equal
124  * and %FALSE otherwise.
125  *
126  * This is a version of #GEqualFunc which provides a @user_data closure from
127  * the caller.
128  *
129  * Returns: %TRUE if @a = @b; %FALSE otherwise
130  * Since: 2.74
131  */
132 typedef gboolean        (*GEqualFuncFull)       (gconstpointer  a,
133                                                  gconstpointer  b,
134                                                  gpointer       user_data);
135
136 typedef void            (*GDestroyNotify)       (gpointer       data);
137 typedef void            (*GFunc)                (gpointer       data,
138                                                  gpointer       user_data);
139 typedef guint           (*GHashFunc)            (gconstpointer  key);
140 typedef void            (*GHFunc)               (gpointer       key,
141                                                  gpointer       value,
142                                                  gpointer       user_data);
143
144 /**
145  * GCopyFunc:
146  * @src: (not nullable): A pointer to the data which should be copied
147  * @user_data: Additional data
148  *
149  * A function of this signature is used to copy the node data
150  * when doing a deep-copy of a tree.
151  *
152  * Returns: (not nullable): A pointer to the copy
153  *
154  * Since: 2.4
155  */
156 typedef gpointer        (*GCopyFunc)            (gconstpointer  src,
157                                                  gpointer       user_data);
158 /**
159  * GFreeFunc:
160  * @data: a data pointer
161  *
162  * Declares a type of function which takes an arbitrary
163  * data pointer argument and has no return value. It is
164  * not currently used in GLib or GTK+.
165  */
166 typedef void            (*GFreeFunc)            (gpointer       data);
167
168 /**
169  * GTranslateFunc:
170  * @str: the untranslated string
171  * @user_data: user data specified when installing the function, e.g.
172  *  in g_option_group_set_translate_func()
173  * 
174  * The type of functions which are used to translate user-visible
175  * strings, for <option>--help</option> output.
176  * 
177  * Returns: a translation of the string for the current locale.
178  *  The returned string is owned by GLib and must not be freed.
179  */
180 typedef const gchar *   (*GTranslateFunc)       (const gchar   *str,
181                                                  gpointer       user_data);
182
183
184 /* Define some mathematical constants that aren't available
185  * symbolically in some strict ISO C implementations.
186  *
187  * Note that the large number of digits used in these definitions
188  * doesn't imply that GLib or current computers in general would be
189  * able to handle floating point numbers with an accuracy like this.
190  * It's mostly an exercise in futility and future proofing. For
191  * extended precision floating point support, look somewhere else
192  * than GLib.
193  */
194 #define G_E     2.7182818284590452353602874713526624977572470937000
195 #define G_LN2   0.69314718055994530941723212145817656807550013436026
196 #define G_LN10  2.3025850929940456840179914546843642076011014886288
197 #define G_PI    3.1415926535897932384626433832795028841971693993751
198 #define G_PI_2  1.5707963267948966192313216916397514420985846996876
199 #define G_PI_4  0.78539816339744830961566084581987572104929234984378
200 #define G_SQRT2 1.4142135623730950488016887242096980785696718753769
201
202 /* Portable endian checks and conversions
203  *
204  * glibconfig.h defines G_BYTE_ORDER which expands to one of
205  * the below macros.
206  */
207 #define G_LITTLE_ENDIAN 1234
208 #define G_BIG_ENDIAN    4321
209 #define G_PDP_ENDIAN    3412            /* unused, need specific PDP check */   
210
211
212 /* Basic bit swapping functions
213  */
214 #define GUINT16_SWAP_LE_BE_CONSTANT(val)        ((guint16) ( \
215     (guint16) ((guint16) (val) >> 8) |  \
216     (guint16) ((guint16) (val) << 8)))
217
218 #define GUINT32_SWAP_LE_BE_CONSTANT(val)        ((guint32) ( \
219     (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \
220     (((guint32) (val) & (guint32) 0x0000ff00U) <<  8) | \
221     (((guint32) (val) & (guint32) 0x00ff0000U) >>  8) | \
222     (((guint32) (val) & (guint32) 0xff000000U) >> 24)))
223
224 #define GUINT64_SWAP_LE_BE_CONSTANT(val)        ((guint64) ( \
225       (((guint64) (val) &                                               \
226         (guint64) G_GINT64_CONSTANT (0x00000000000000ffU)) << 56) |     \
227       (((guint64) (val) &                                               \
228         (guint64) G_GINT64_CONSTANT (0x000000000000ff00U)) << 40) |     \
229       (((guint64) (val) &                                               \
230         (guint64) G_GINT64_CONSTANT (0x0000000000ff0000U)) << 24) |     \
231       (((guint64) (val) &                                               \
232         (guint64) G_GINT64_CONSTANT (0x00000000ff000000U)) <<  8) |     \
233       (((guint64) (val) &                                               \
234         (guint64) G_GINT64_CONSTANT (0x000000ff00000000U)) >>  8) |     \
235       (((guint64) (val) &                                               \
236         (guint64) G_GINT64_CONSTANT (0x0000ff0000000000U)) >> 24) |     \
237       (((guint64) (val) &                                               \
238         (guint64) G_GINT64_CONSTANT (0x00ff000000000000U)) >> 40) |     \
239       (((guint64) (val) &                                               \
240         (guint64) G_GINT64_CONSTANT (0xff00000000000000U)) >> 56)))
241
242 /* Arch specific stuff for speed
243  */
244 #if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__)
245
246 #  if __GNUC__ >= 4 && defined (__GNUC_MINOR__) && __GNUC_MINOR__ >= 3
247 #    define GUINT32_SWAP_LE_BE(val) ((guint32) __builtin_bswap32 ((guint32) (val)))
248 #    define GUINT64_SWAP_LE_BE(val) ((guint64) __builtin_bswap64 ((guint64) (val)))
249 #  endif
250
251 #  if defined (__i386__)
252 #    define GUINT16_SWAP_LE_BE_IA32(val) \
253        (G_GNUC_EXTENSION                                        \
254         ({ guint16 __v, __x = ((guint16) (val));                \
255            if (__builtin_constant_p (__x))                      \
256              __v = GUINT16_SWAP_LE_BE_CONSTANT (__x);           \
257            else                                                 \
258              __asm__ ("rorw $8, %w0"                            \
259                       : "=r" (__v)                              \
260                       : "0" (__x)                               \
261                       : "cc");                                  \
262             __v; }))
263 #    if !defined (__i486__) && !defined (__i586__) \
264         && !defined (__pentium__) && !defined (__i686__) \
265         && !defined (__pentiumpro__) && !defined (__pentium4__)
266 #       define GUINT32_SWAP_LE_BE_IA32(val) \
267           (G_GNUC_EXTENSION                                     \
268            ({ guint32 __v, __x = ((guint32) (val));             \
269               if (__builtin_constant_p (__x))                   \
270                 __v = GUINT32_SWAP_LE_BE_CONSTANT (__x);        \
271               else                                              \
272                 __asm__ ("rorw $8, %w0\n\t"                     \
273                          "rorl $16, %0\n\t"                     \
274                          "rorw $8, %w0"                         \
275                          : "=r" (__v)                           \
276                          : "0" (__x)                            \
277                          : "cc");                               \
278               __v; }))
279 #    else /* 486 and higher has bswap */
280 #       define GUINT32_SWAP_LE_BE_IA32(val) \
281           (G_GNUC_EXTENSION                                     \
282            ({ guint32 __v, __x = ((guint32) (val));             \
283               if (__builtin_constant_p (__x))                   \
284                 __v = GUINT32_SWAP_LE_BE_CONSTANT (__x);        \
285               else                                              \
286                 __asm__ ("bswap %0"                             \
287                          : "=r" (__v)                           \
288                          : "0" (__x));                          \
289               __v; }))
290 #    endif /* processor specific 32-bit stuff */
291 #    define GUINT64_SWAP_LE_BE_IA32(val) \
292        (G_GNUC_EXTENSION                                                \
293         ({ union { guint64 __ll;                                        \
294                    guint32 __l[2]; } __w, __r;                          \
295            __w.__ll = ((guint64) (val));                                \
296            if (__builtin_constant_p (__w.__ll))                         \
297              __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (__w.__ll);         \
298            else                                                         \
299              {                                                          \
300                __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]);            \
301                __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]);            \
302              }                                                          \
303            __r.__ll; }))
304      /* Possibly just use the constant version and let gcc figure it out? */
305 #    define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_IA32 (val))
306 #    ifndef GUINT32_SWAP_LE_BE
307 #      define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_IA32 (val))
308 #    endif
309 #    ifndef GUINT64_SWAP_LE_BE
310 #      define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_IA32 (val))
311 #    endif
312 #  elif defined (__ia64__)
313 #    define GUINT16_SWAP_LE_BE_IA64(val) \
314        (G_GNUC_EXTENSION                                        \
315         ({ guint16 __v, __x = ((guint16) (val));                \
316            if (__builtin_constant_p (__x))                      \
317              __v = GUINT16_SWAP_LE_BE_CONSTANT (__x);           \
318            else                                                 \
319              __asm__ __volatile__ ("shl %0 = %1, 48 ;;"         \
320                                    "mux1 %0 = %0, @rev ;;"      \
321                                     : "=r" (__v)                \
322                                     : "r" (__x));               \
323             __v; }))
324 #    define GUINT32_SWAP_LE_BE_IA64(val) \
325        (G_GNUC_EXTENSION                                        \
326          ({ guint32 __v, __x = ((guint32) (val));               \
327             if (__builtin_constant_p (__x))                     \
328               __v = GUINT32_SWAP_LE_BE_CONSTANT (__x);          \
329             else                                                \
330              __asm__ __volatile__ ("shl %0 = %1, 32 ;;"         \
331                                    "mux1 %0 = %0, @rev ;;"      \
332                                     : "=r" (__v)                \
333                                     : "r" (__x));               \
334             __v; }))
335 #    define GUINT64_SWAP_LE_BE_IA64(val) \
336        (G_GNUC_EXTENSION                                        \
337         ({ guint64 __v, __x = ((guint64) (val));                \
338            if (__builtin_constant_p (__x))                      \
339              __v = GUINT64_SWAP_LE_BE_CONSTANT (__x);           \
340            else                                                 \
341              __asm__ __volatile__ ("mux1 %0 = %1, @rev ;;"      \
342                                    : "=r" (__v)                 \
343                                    : "r" (__x));                \
344            __v; }))
345 #    define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_IA64 (val))
346 #    ifndef GUINT32_SWAP_LE_BE
347 #      define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_IA64 (val))
348 #    endif
349 #    ifndef GUINT64_SWAP_LE_BE
350 #      define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_IA64 (val))
351 #    endif
352 #  elif defined (__x86_64__)
353 #    define GUINT32_SWAP_LE_BE_X86_64(val) \
354        (G_GNUC_EXTENSION                                        \
355          ({ guint32 __v, __x = ((guint32) (val));               \
356             if (__builtin_constant_p (__x))                     \
357               __v = GUINT32_SWAP_LE_BE_CONSTANT (__x);          \
358             else                                                \
359              __asm__ ("bswapl %0"                               \
360                       : "=r" (__v)                              \
361                       : "0" (__x));                             \
362             __v; }))
363 #    define GUINT64_SWAP_LE_BE_X86_64(val) \
364        (G_GNUC_EXTENSION                                        \
365         ({ guint64 __v, __x = ((guint64) (val));                \
366            if (__builtin_constant_p (__x))                      \
367              __v = GUINT64_SWAP_LE_BE_CONSTANT (__x);           \
368            else                                                 \
369              __asm__ ("bswapq %0"                               \
370                       : "=r" (__v)                              \
371                       : "0" (__x));                             \
372            __v; }))
373      /* gcc seems to figure out optimal code for this on its own */
374 #    define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
375 #    ifndef GUINT32_SWAP_LE_BE
376 #      define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86_64 (val))
377 #    endif
378 #    ifndef GUINT64_SWAP_LE_BE
379 #      define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86_64 (val))
380 #    endif
381 #  else /* generic gcc */
382 #    define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
383 #    ifndef GUINT32_SWAP_LE_BE
384 #      define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
385 #    endif
386 #    ifndef GUINT64_SWAP_LE_BE
387 #      define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT (val))
388 #    endif
389 #  endif
390 #else /* generic */
391 #  define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
392 #  define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
393 #  define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT (val))
394 #endif /* generic */
395
396 #define GUINT16_SWAP_LE_PDP(val)        ((guint16) (val))
397 #define GUINT16_SWAP_BE_PDP(val)        (GUINT16_SWAP_LE_BE (val))
398 #define GUINT32_SWAP_LE_PDP(val)        ((guint32) ( \
399     (((guint32) (val) & (guint32) 0x0000ffffU) << 16) | \
400     (((guint32) (val) & (guint32) 0xffff0000U) >> 16)))
401 #define GUINT32_SWAP_BE_PDP(val)        ((guint32) ( \
402     (((guint32) (val) & (guint32) 0x00ff00ffU) << 8) | \
403     (((guint32) (val) & (guint32) 0xff00ff00U) >> 8)))
404
405 /* The G*_TO_?E() macros are defined in glibconfig.h.
406  * The transformation is symmetric, so the FROM just maps to the TO.
407  */
408 #define GINT16_FROM_LE(val)     (GINT16_TO_LE (val))
409 #define GUINT16_FROM_LE(val)    (GUINT16_TO_LE (val))
410 #define GINT16_FROM_BE(val)     (GINT16_TO_BE (val))
411 #define GUINT16_FROM_BE(val)    (GUINT16_TO_BE (val))
412 #define GINT32_FROM_LE(val)     (GINT32_TO_LE (val))
413 #define GUINT32_FROM_LE(val)    (GUINT32_TO_LE (val))
414 #define GINT32_FROM_BE(val)     (GINT32_TO_BE (val))
415 #define GUINT32_FROM_BE(val)    (GUINT32_TO_BE (val))
416
417 #define GINT64_FROM_LE(val)     (GINT64_TO_LE (val))
418 #define GUINT64_FROM_LE(val)    (GUINT64_TO_LE (val))
419 #define GINT64_FROM_BE(val)     (GINT64_TO_BE (val))
420 #define GUINT64_FROM_BE(val)    (GUINT64_TO_BE (val))
421
422 #define GLONG_FROM_LE(val)      (GLONG_TO_LE (val))
423 #define GULONG_FROM_LE(val)     (GULONG_TO_LE (val))
424 #define GLONG_FROM_BE(val)      (GLONG_TO_BE (val))
425 #define GULONG_FROM_BE(val)     (GULONG_TO_BE (val))
426
427 #define GINT_FROM_LE(val)       (GINT_TO_LE (val))
428 #define GUINT_FROM_LE(val)      (GUINT_TO_LE (val))
429 #define GINT_FROM_BE(val)       (GINT_TO_BE (val))
430 #define GUINT_FROM_BE(val)      (GUINT_TO_BE (val))
431
432 #define GSIZE_FROM_LE(val)      (GSIZE_TO_LE (val))
433 #define GSSIZE_FROM_LE(val)     (GSSIZE_TO_LE (val))
434 #define GSIZE_FROM_BE(val)      (GSIZE_TO_BE (val))
435 #define GSSIZE_FROM_BE(val)     (GSSIZE_TO_BE (val))
436
437 /* Portable versions of host-network order stuff
438  */
439 #define g_ntohl(val) (GUINT32_FROM_BE (val))
440 #define g_ntohs(val) (GUINT16_FROM_BE (val))
441 #define g_htonl(val) (GUINT32_TO_BE (val))
442 #define g_htons(val) (GUINT16_TO_BE (val))
443
444 /* Overflow-checked unsigned integer arithmetic
445  */
446 #ifndef _GLIB_TEST_OVERFLOW_FALLBACK
447 /* https://bugzilla.gnome.org/show_bug.cgi?id=769104 */
448 #if __GNUC__ >= 5 && !defined(__INTEL_COMPILER)
449 #define _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS
450 #elif g_macro__has_builtin(__builtin_add_overflow)
451 #define _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS
452 #endif
453 #endif
454
455 #ifdef _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS
456
457 #define g_uint_checked_add(dest, a, b) \
458     (!__builtin_add_overflow(a, b, dest))
459 #define g_uint_checked_mul(dest, a, b) \
460     (!__builtin_mul_overflow(a, b, dest))
461
462 #define g_uint64_checked_add(dest, a, b) \
463     (!__builtin_add_overflow(a, b, dest))
464 #define g_uint64_checked_mul(dest, a, b) \
465     (!__builtin_mul_overflow(a, b, dest))
466
467 #define g_size_checked_add(dest, a, b) \
468     (!__builtin_add_overflow(a, b, dest))
469 #define g_size_checked_mul(dest, a, b) \
470     (!__builtin_mul_overflow(a, b, dest))
471
472 #else  /* !_GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS */
473
474 /* The names of the following inlines are private.  Use the macro
475  * definitions above.
476  */
477 static inline gboolean _GLIB_CHECKED_ADD_UINT (guint *dest, guint a, guint b) {
478   *dest = a + b; return *dest >= a; }
479 static inline gboolean _GLIB_CHECKED_MUL_UINT (guint *dest, guint a, guint b) {
480   *dest = a * b; return !a || *dest / a == b; }
481 static inline gboolean _GLIB_CHECKED_ADD_UINT64 (guint64 *dest, guint64 a, guint64 b) {
482   *dest = a + b; return *dest >= a; }
483 static inline gboolean _GLIB_CHECKED_MUL_UINT64 (guint64 *dest, guint64 a, guint64 b) {
484   *dest = a * b; return !a || *dest / a == b; }
485 static inline gboolean _GLIB_CHECKED_ADD_SIZE (gsize *dest, gsize a, gsize b) {
486   *dest = a + b; return *dest >= a; }
487 static inline gboolean _GLIB_CHECKED_MUL_SIZE (gsize *dest, gsize a, gsize b) {
488   *dest = a * b; return !a || *dest / a == b; }
489
490 #define g_uint_checked_add(dest, a, b) \
491     _GLIB_CHECKED_ADD_UINT(dest, a, b)
492 #define g_uint_checked_mul(dest, a, b) \
493     _GLIB_CHECKED_MUL_UINT(dest, a, b)
494
495 #define g_uint64_checked_add(dest, a, b) \
496     _GLIB_CHECKED_ADD_UINT64(dest, a, b)
497 #define g_uint64_checked_mul(dest, a, b) \
498     _GLIB_CHECKED_MUL_UINT64(dest, a, b)
499
500 #define g_size_checked_add(dest, a, b) \
501     _GLIB_CHECKED_ADD_SIZE(dest, a, b)
502 #define g_size_checked_mul(dest, a, b) \
503     _GLIB_CHECKED_MUL_SIZE(dest, a, b)
504
505 #endif  /* !_GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS */
506
507 /* IEEE Standard 754 Single Precision Storage Format (gfloat):
508  *
509  *        31 30           23 22            0
510  * +--------+---------------+---------------+
511  * | s 1bit | e[30:23] 8bit | f[22:0] 23bit |
512  * +--------+---------------+---------------+
513  * B0------------------->B1------->B2-->B3-->
514  *
515  * IEEE Standard 754 Double Precision Storage Format (gdouble):
516  *
517  *        63 62            52 51            32   31            0
518  * +--------+----------------+----------------+ +---------------+
519  * | s 1bit | e[62:52] 11bit | f[51:32] 20bit | | f[31:0] 32bit |
520  * +--------+----------------+----------------+ +---------------+
521  * B0--------------->B1---------->B2--->B3---->  B4->B5->B6->B7->
522  */
523 /* subtract from biased_exponent to form base2 exponent (normal numbers) */
524 typedef union  _GDoubleIEEE754  GDoubleIEEE754;
525 typedef union  _GFloatIEEE754   GFloatIEEE754;
526 #define G_IEEE754_FLOAT_BIAS    (127)
527 #define G_IEEE754_DOUBLE_BIAS   (1023)
528 /* multiply with base2 exponent to get base10 exponent (normal numbers) */
529 #define G_LOG_2_BASE_10         (0.30102999566398119521)
530 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
531 union _GFloatIEEE754
532 {
533   gfloat v_float;
534   struct {
535     guint mantissa : 23;
536     guint biased_exponent : 8;
537     guint sign : 1;
538   } mpn;
539 };
540 union _GDoubleIEEE754
541 {
542   gdouble v_double;
543   struct {
544     guint mantissa_low : 32;
545     guint mantissa_high : 20;
546     guint biased_exponent : 11;
547     guint sign : 1;
548   } mpn;
549 };
550 #elif G_BYTE_ORDER == G_BIG_ENDIAN
551 union _GFloatIEEE754
552 {
553   gfloat v_float;
554   struct {
555     guint sign : 1;
556     guint biased_exponent : 8;
557     guint mantissa : 23;
558   } mpn;
559 };
560 union _GDoubleIEEE754
561 {
562   gdouble v_double;
563   struct {
564     guint sign : 1;
565     guint biased_exponent : 11;
566     guint mantissa_high : 20;
567     guint mantissa_low : 32;
568   } mpn;
569 };
570 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
571 #error unknown ENDIAN type
572 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
573
574 typedef struct _GTimeVal GTimeVal GLIB_DEPRECATED_TYPE_IN_2_62_FOR(GDateTime);
575
576 struct _GTimeVal
577 {
578   glong tv_sec;
579   glong tv_usec;
580 } GLIB_DEPRECATED_TYPE_IN_2_62_FOR(GDateTime);
581
582 typedef gint grefcount;
583 typedef gint gatomicrefcount;  /* should be accessed only using atomics */
584
585 G_END_DECLS
586
587 /* We prefix variable declarations so they can
588  * properly get exported in Windows DLLs.
589  */
590 #ifndef GLIB_VAR
591 #  ifdef G_PLATFORM_WIN32
592 #    ifdef GLIB_STATIC_COMPILATION
593 #      define GLIB_VAR extern
594 #    else /* !GLIB_STATIC_COMPILATION */
595 #      ifdef GLIB_COMPILATION
596 #        ifdef DLL_EXPORT
597 #          define GLIB_VAR extern __declspec(dllexport)
598 #        else /* !DLL_EXPORT */
599 #          define GLIB_VAR extern
600 #        endif /* !DLL_EXPORT */
601 #      else /* !GLIB_COMPILATION */
602 #        define GLIB_VAR extern __declspec(dllimport)
603 #      endif /* !GLIB_COMPILATION */
604 #    endif /* !GLIB_STATIC_COMPILATION */
605 #  else /* !G_PLATFORM_WIN32 */
606 #    define GLIB_VAR _GLIB_EXTERN
607 #  endif /* !G_PLATFORM_WIN32 */
608 #endif /* GLIB_VAR */
609
610 #endif /* __G_TYPES_H__ */