meson: Bump up timeout for slow test
[glib.git] / glib / docs.c
blob5031a6225d73e028e00e99b5dc46f6ea8513a46e
1 /*
2 * Copyright © 2011 Red Hat, Inc
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 * Author: Matthias Clasen
21 /* This file collects documentation for macros, typedefs and
22 * the like, which have no good home in any of the 'real' source
23 * files.
26 /* Basic types {{{1 */
28 /**
29 * SECTION:types
30 * @title: Basic Types
31 * @short_description: standard GLib types, defined for ease-of-use
32 * and portability
34 * GLib defines a number of commonly used types, which can be divided
35 * into several groups:
36 * - New types which are not part of standard C (but are defined in
37 * various C standard library header files) — #gboolean, #gssize.
38 * - Integer types which are guaranteed to be the same size across
39 * all platforms — #gint8, #guint8, #gint16, #guint16, #gint32,
40 * #guint32, #gint64, #guint64.
41 * - Types which are easier to use than their standard C counterparts -
42 * #gpointer, #gconstpointer, #guchar, #guint, #gushort, #gulong.
43 * - Types which correspond exactly to standard C types, but are
44 * included for completeness — #gchar, #gint, #gshort, #glong,
45 * #gfloat, #gdouble.
46 * - Types which correspond exactly to standard C99 types, but are available
47 * to use even if your compiler does not support C99 — #gsize, #goffset,
48 * #gintptr, #guintptr.
50 * GLib also defines macros for the limits of some of the standard
51 * integer and floating point types, as well as macros for suitable
52 * printf() formats for these types.
55 /**
56 * gboolean:
58 * A standard boolean type.
59 * Variables of this type should only contain the value
60 * %TRUE or %FALSE.
63 /**
64 * gpointer:
66 * An untyped pointer.
67 * #gpointer looks better and is easier to use than void*.
70 /**
71 * gconstpointer:
73 * An untyped pointer to constant data.
74 * The data pointed to should not be changed.
76 * This is typically used in function prototypes to indicate
77 * that the data pointed to will not be altered by the function.
80 /**
81 * gchar:
83 * Corresponds to the standard C char type.
86 /**
87 * guchar:
89 * Corresponds to the standard C unsigned char type.
92 /**
93 * gint:
95 * Corresponds to the standard C int type.
96 * Values of this type can range from #G_MININT to #G_MAXINT.
99 /**
100 * G_MININT:
102 * The minimum value which can be held in a #gint.
106 * G_MAXINT:
108 * The maximum value which can be held in a #gint.
112 * guint:
114 * Corresponds to the standard C unsigned int type.
115 * Values of this type can range from 0 to #G_MAXUINT.
119 * G_MAXUINT:
121 * The maximum value which can be held in a #guint.
125 * gshort:
127 * Corresponds to the standard C short type.
128 * Values of this type can range from #G_MINSHORT to #G_MAXSHORT.
132 * G_MINSHORT:
134 * The minimum value which can be held in a #gshort.
138 * G_MAXSHORT:
140 * The maximum value which can be held in a #gshort.
144 * gushort:
146 * Corresponds to the standard C unsigned short type.
147 * Values of this type can range from 0 to #G_MAXUSHORT.
151 * G_MAXUSHORT:
153 * The maximum value which can be held in a #gushort.
157 * glong:
159 * Corresponds to the standard C long type.
160 * Values of this type can range from #G_MINLONG to #G_MAXLONG.
164 * G_MINLONG:
166 * The minimum value which can be held in a #glong.
170 * G_MAXLONG:
172 * The maximum value which can be held in a #glong.
176 * gulong:
178 * Corresponds to the standard C unsigned long type.
179 * Values of this type can range from 0 to #G_MAXULONG.
183 * G_MAXULONG:
185 * The maximum value which can be held in a #gulong.
189 * gint8:
191 * A signed integer guaranteed to be 8 bits on all platforms.
192 * Values of this type can range from #G_MININT8 (= -128) to
193 * #G_MAXINT8 (= 127).
197 * G_MININT8:
199 * The minimum value which can be held in a #gint8.
201 * Since: 2.4
205 * G_MAXINT8:
207 * The maximum value which can be held in a #gint8.
209 * Since: 2.4
213 * guint8:
215 * An unsigned integer guaranteed to be 8 bits on all platforms.
216 * Values of this type can range from 0 to #G_MAXUINT8 (= 255).
220 * G_MAXUINT8:
222 * The maximum value which can be held in a #guint8.
224 * Since: 2.4
228 * gint16:
230 * A signed integer guaranteed to be 16 bits on all platforms.
231 * Values of this type can range from #G_MININT16 (= -32,768) to
232 * #G_MAXINT16 (= 32,767).
234 * To print or scan values of this type, use
235 * %G_GINT16_MODIFIER and/or %G_GINT16_FORMAT.
239 * G_MININT16:
241 * The minimum value which can be held in a #gint16.
243 * Since: 2.4
247 * G_MAXINT16:
249 * The maximum value which can be held in a #gint16.
251 * Since: 2.4
255 * G_GINT16_MODIFIER:
257 * The platform dependent length modifier for conversion specifiers
258 * for scanning and printing values of type #gint16 or #guint16. It
259 * is a string literal, but doesn't include the percent-sign, such
260 * that you can add precision and length modifiers between percent-sign
261 * and conversion specifier and append a conversion specifier.
263 * The following example prints "0x7b";
264 * |[<!-- language="C" -->
265 * gint16 value = 123;
266 * g_print ("%#" G_GINT16_MODIFIER "x", value);
267 * ]|
269 * Since: 2.4
273 * G_GINT16_FORMAT:
275 * This is the platform dependent conversion specifier for scanning and
276 * printing values of type #gint16. It is a string literal, but doesn't
277 * include the percent-sign, such that you can add precision and length
278 * modifiers between percent-sign and conversion specifier.
280 * |[<!-- language="C" -->
281 * gint16 in;
282 * gint32 out;
283 * sscanf ("42", "%" G_GINT16_FORMAT, &in)
284 * out = in * 1000;
285 * g_print ("%" G_GINT32_FORMAT, out);
286 * ]|
290 * guint16:
292 * An unsigned integer guaranteed to be 16 bits on all platforms.
293 * Values of this type can range from 0 to #G_MAXUINT16 (= 65,535).
295 * To print or scan values of this type, use
296 * %G_GINT16_MODIFIER and/or %G_GUINT16_FORMAT.
300 * G_MAXUINT16:
302 * The maximum value which can be held in a #guint16.
304 * Since: 2.4
308 * G_GUINT16_FORMAT:
310 * This is the platform dependent conversion specifier for scanning
311 * and printing values of type #guint16. See also #G_GINT16_FORMAT
315 * gint32:
317 * A signed integer guaranteed to be 32 bits on all platforms.
318 * Values of this type can range from #G_MININT32 (= -2,147,483,648)
319 * to #G_MAXINT32 (= 2,147,483,647).
321 * To print or scan values of this type, use
322 * %G_GINT32_MODIFIER and/or %G_GINT32_FORMAT.
326 * G_MININT32:
328 * The minimum value which can be held in a #gint32.
330 * Since: 2.4
334 * G_MAXINT32:
336 * The maximum value which can be held in a #gint32.
338 * Since: 2.4
342 * G_GINT32_MODIFIER:
344 * The platform dependent length modifier for conversion specifiers
345 * for scanning and printing values of type #gint32 or #guint32. It
346 * is a string literal. See also #G_GINT16_MODIFIER.
348 * Since: 2.4
352 * G_GINT32_FORMAT:
354 * This is the platform dependent conversion specifier for scanning
355 * and printing values of type #gint32. See also #G_GINT16_FORMAT.
359 * guint32:
361 * An unsigned integer guaranteed to be 32 bits on all platforms.
362 * Values of this type can range from 0 to #G_MAXUINT32 (= 4,294,967,295).
364 * To print or scan values of this type, use
365 * %G_GINT32_MODIFIER and/or %G_GUINT32_FORMAT.
369 * G_MAXUINT32:
371 * The maximum value which can be held in a #guint32.
373 * Since: 2.4
377 * G_GUINT32_FORMAT:
379 * This is the platform dependent conversion specifier for scanning
380 * and printing values of type #guint32. See also #G_GINT16_FORMAT.
384 * gint64:
386 * A signed integer guaranteed to be 64 bits on all platforms.
387 * Values of this type can range from #G_MININT64
388 * (= -9,223,372,036,854,775,808) to #G_MAXINT64
389 * (= 9,223,372,036,854,775,807).
391 * To print or scan values of this type, use
392 * %G_GINT64_MODIFIER and/or %G_GINT64_FORMAT.
396 * G_MININT64:
398 * The minimum value which can be held in a #gint64.
402 * G_MAXINT64:
404 * The maximum value which can be held in a #gint64.
408 * G_GINT64_MODIFIER:
410 * The platform dependent length modifier for conversion specifiers
411 * for scanning and printing values of type #gint64 or #guint64.
412 * It is a string literal.
414 * Some platforms do not support printing 64-bit integers, even
415 * though the types are supported. On such platforms %G_GINT64_MODIFIER
416 * is not defined.
418 * Since: 2.4
422 * G_GINT64_FORMAT:
424 * This is the platform dependent conversion specifier for scanning
425 * and printing values of type #gint64. See also #G_GINT16_FORMAT.
427 * Some platforms do not support scanning and printing 64-bit integers,
428 * even though the types are supported. On such platforms %G_GINT64_FORMAT
429 * is not defined. Note that scanf() may not support 64-bit integers, even
430 * if %G_GINT64_FORMAT is defined. Due to its weak error handling, scanf()
431 * is not recommended for parsing anyway; consider using g_ascii_strtoull()
432 * instead.
436 * guint64:
438 * An unsigned integer guaranteed to be 64-bits on all platforms.
439 * Values of this type can range from 0 to #G_MAXUINT64
440 * (= 18,446,744,073,709,551,615).
442 * To print or scan values of this type, use
443 * %G_GINT64_MODIFIER and/or %G_GUINT64_FORMAT.
447 * G_MAXUINT64:
449 * The maximum value which can be held in a #guint64.
453 * G_GUINT64_FORMAT:
455 * This is the platform dependent conversion specifier for scanning
456 * and printing values of type #guint64. See also #G_GINT16_FORMAT.
458 * Some platforms do not support scanning and printing 64-bit integers,
459 * even though the types are supported. On such platforms %G_GUINT64_FORMAT
460 * is not defined. Note that scanf() may not support 64-bit integers, even
461 * if %G_GINT64_FORMAT is defined. Due to its weak error handling, scanf()
462 * is not recommended for parsing anyway; consider using g_ascii_strtoull()
463 * instead.
467 * G_GINT64_CONSTANT:
468 * @val: a literal integer value, e.g. 0x1d636b02300a7aa7
470 * This macro is used to insert 64-bit integer literals
471 * into the source code.
475 * G_GUINT64_CONSTANT:
476 * @val: a literal integer value, e.g. 0x1d636b02300a7aa7U
478 * This macro is used to insert 64-bit unsigned integer
479 * literals into the source code.
481 * Since: 2.10
485 * gfloat:
487 * Corresponds to the standard C float type.
488 * Values of this type can range from -#G_MAXFLOAT to #G_MAXFLOAT.
492 * G_MINFLOAT:
494 * The minimum positive value which can be held in a #gfloat.
496 * If you are interested in the smallest value which can be held
497 * in a #gfloat, use -%G_MAXFLOAT.
501 * G_MAXFLOAT:
503 * The maximum value which can be held in a #gfloat.
507 * gdouble:
509 * Corresponds to the standard C double type.
510 * Values of this type can range from -#G_MAXDOUBLE to #G_MAXDOUBLE.
514 * G_MINDOUBLE:
516 * The minimum positive value which can be held in a #gdouble.
518 * If you are interested in the smallest value which can be held
519 * in a #gdouble, use -%G_MAXDOUBLE.
523 * G_MAXDOUBLE:
525 * The maximum value which can be held in a #gdouble.
529 * gsize:
531 * An unsigned integer type of the result of the sizeof operator,
532 * corresponding to the size_t type defined in C99.
533 * This type is wide enough to hold the numeric value of a pointer,
534 * so it is usually 32 bit wide on a 32-bit platform and 64 bit wide
535 * on a 64-bit platform. Values of this type can range from 0 to
536 * #G_MAXSIZE.
538 * To print or scan values of this type, use
539 * %G_GSIZE_MODIFIER and/or %G_GSIZE_FORMAT.
543 * G_MAXSIZE:
545 * The maximum value which can be held in a #gsize.
547 * Since: 2.4
551 * G_GSIZE_MODIFIER:
553 * The platform dependent length modifier for conversion specifiers
554 * for scanning and printing values of type #gsize. It
555 * is a string literal.
557 * Since: 2.6
561 * G_GSIZE_FORMAT:
563 * This is the platform dependent conversion specifier for scanning
564 * and printing values of type #gsize. See also #G_GINT16_FORMAT.
566 * Since: 2.6
570 * gssize:
572 * A signed variant of #gsize, corresponding to the
573 * ssize_t defined on most platforms.
574 * Values of this type can range from #G_MINSSIZE
575 * to #G_MAXSSIZE.
577 * To print or scan values of this type, use
578 * %G_GSSIZE_MODIFIER and/or %G_GSSIZE_FORMAT.
582 * G_MINSSIZE:
584 * The minimum value which can be held in a #gssize.
586 * Since: 2.14
590 * G_MAXSSIZE:
592 * The maximum value which can be held in a #gssize.
594 * Since: 2.14
598 * G_GSSIZE_FORMAT:
600 * This is the platform dependent conversion specifier for scanning
601 * and printing values of type #gssize. See also #G_GINT16_FORMAT.
603 * Since: 2.6
607 * G_GSSIZE_MODIFIER:
609 * The platform dependent length modifier for conversion specifiers
610 * for scanning and printing values of type #gssize. It
611 * is a string literal.
613 * Since: 2.6
617 * goffset:
619 * A signed integer type that is used for file offsets,
620 * corresponding to the POSIX type `off_t` as if compiling with
621 * `_FILE_OFFSET_BITS` set to 64. #goffset is always 64 bits wide, even on
622 * 32-bit architectures.
623 * Values of this type can range from #G_MINOFFSET to
624 * #G_MAXOFFSET.
626 * To print or scan values of this type, use
627 * %G_GOFFSET_MODIFIER and/or %G_GOFFSET_FORMAT.
629 * Since: 2.14
633 * G_MINOFFSET:
635 * The minimum value which can be held in a #goffset.
639 * G_MAXOFFSET:
641 * The maximum value which can be held in a #goffset.
645 * G_GOFFSET_MODIFIER:
647 * The platform dependent length modifier for conversion specifiers
648 * for scanning and printing values of type #goffset. It is a string
649 * literal. See also #G_GINT64_MODIFIER.
651 * Since: 2.20
655 * G_GOFFSET_FORMAT:
657 * This is the platform dependent conversion specifier for scanning
658 * and printing values of type #goffset. See also #G_GINT64_FORMAT.
660 * Since: 2.20
664 * G_GOFFSET_CONSTANT:
665 * @val: a literal integer value, e.g. 0x1d636b02300a7aa7
667 * This macro is used to insert #goffset 64-bit integer literals
668 * into the source code.
670 * See also #G_GINT64_CONSTANT.
672 * Since: 2.20
676 * gintptr:
678 * Corresponds to the C99 type intptr_t,
679 * a signed integer type that can hold any pointer.
681 * To print or scan values of this type, use
682 * %G_GINTPTR_MODIFIER and/or %G_GINTPTR_FORMAT.
684 * Since: 2.18
688 * G_GINTPTR_MODIFIER:
690 * The platform dependent length modifier for conversion specifiers
691 * for scanning and printing values of type #gintptr or #guintptr.
692 * It is a string literal.
694 * Since: 2.22
698 * G_GINTPTR_FORMAT:
700 * This is the platform dependent conversion specifier for scanning
701 * and printing values of type #gintptr.
703 * Since: 2.22
707 * guintptr:
709 * Corresponds to the C99 type uintptr_t,
710 * an unsigned integer type that can hold any pointer.
712 * To print or scan values of this type, use
713 * %G_GINTPTR_MODIFIER and/or %G_GUINTPTR_FORMAT.
715 * Since: 2.18
719 * G_GUINTPTR_FORMAT:
721 * This is the platform dependent conversion specifier
722 * for scanning and printing values of type #guintptr.
724 * Since: 2.22
727 /* Type conversion {{{1 */
730 * SECTION:type_conversion
731 * @title: Type Conversion Macros
732 * @short_description: portably storing integers in pointer variables
734 * Many times GLib, GTK+, and other libraries allow you to pass "user
735 * data" to a callback, in the form of a void pointer. From time to time
736 * you want to pass an integer instead of a pointer. You could allocate
737 * an integer, with something like:
738 * |[<!-- language="C" -->
739 * int *ip = g_new (int, 1);
740 * *ip = 42;
741 * ]|
742 * But this is inconvenient, and it's annoying to have to free the
743 * memory at some later time.
745 * Pointers are always at least 32 bits in size (on all platforms GLib
746 * intends to support). Thus you can store at least 32-bit integer values
747 * in a pointer value. Naively, you might try this, but it's incorrect:
748 * |[<!-- language="C" -->
749 * gpointer p;
750 * int i;
751 * p = (void*) 42;
752 * i = (int) p;
753 * ]|
754 * Again, that example was not correct, don't copy it.
755 * The problem is that on some systems you need to do this:
756 * |[<!-- language="C" -->
757 * gpointer p;
758 * int i;
759 * p = (void*) (long) 42;
760 * i = (int) (long) p;
761 * ]|
762 * The GLib macros GPOINTER_TO_INT(), GINT_TO_POINTER(), etc. take care
763 * to do the right thing on the every platform.
765 * Warning: You may not store pointers in integers. This is not
766 * portable in any way, shape or form. These macros only allow storing
767 * integers in pointers, and only preserve 32 bits of the integer; values
768 * outside the range of a 32-bit integer will be mangled.
772 * GINT_TO_POINTER:
773 * @i: integer to stuff into a pointer
775 * Stuffs an integer into a pointer type.
777 * Remember, you may not store pointers in integers. This is not portable
778 * in any way, shape or form. These macros only allow storing integers in
779 * pointers, and only preserve 32 bits of the integer; values outside the
780 * range of a 32-bit integer will be mangled.
784 * GPOINTER_TO_INT:
785 * @p: pointer containing an integer
787 * Extracts an integer from a pointer. The integer must have
788 * been stored in the pointer with GINT_TO_POINTER().
790 * Remember, you may not store pointers in integers. This is not portable
791 * in any way, shape or form. These macros only allow storing integers in
792 * pointers, and only preserve 32 bits of the integer; values outside the
793 * range of a 32-bit integer will be mangled.
797 * GUINT_TO_POINTER:
798 * @u: unsigned integer to stuff into the pointer
800 * Stuffs an unsigned integer into a pointer type.
804 * GPOINTER_TO_UINT:
805 * @p: pointer to extract an unsigned integer from
807 * Extracts an unsigned integer from a pointer. The integer must have
808 * been stored in the pointer with GUINT_TO_POINTER().
812 * GSIZE_TO_POINTER:
813 * @s: #gsize to stuff into the pointer
815 * Stuffs a #gsize into a pointer type.
819 * GPOINTER_TO_SIZE:
820 * @p: pointer to extract a #gsize from
822 * Extracts a #gsize from a pointer. The #gsize must have
823 * been stored in the pointer with GSIZE_TO_POINTER().
826 /* Byte order {{{1 */
829 * SECTION:byte_order
830 * @title: Byte Order Macros
831 * @short_description: a portable way to convert between different byte orders
833 * These macros provide a portable way to determine the host byte order
834 * and to convert values between different byte orders.
836 * The byte order is the order in which bytes are stored to create larger
837 * data types such as the #gint and #glong values.
838 * The host byte order is the byte order used on the current machine.
840 * Some processors store the most significant bytes (i.e. the bytes that
841 * hold the largest part of the value) first. These are known as big-endian
842 * processors. Other processors (notably the x86 family) store the most
843 * significant byte last. These are known as little-endian processors.
845 * Finally, to complicate matters, some other processors store the bytes in
846 * a rather curious order known as PDP-endian. For a 4-byte word, the 3rd
847 * most significant byte is stored first, then the 4th, then the 1st and
848 * finally the 2nd.
850 * Obviously there is a problem when these different processors communicate
851 * with each other, for example over networks or by using binary file formats.
852 * This is where these macros come in. They are typically used to convert
853 * values into a byte order which has been agreed on for use when
854 * communicating between different processors. The Internet uses what is
855 * known as 'network byte order' as the standard byte order (which is in
856 * fact the big-endian byte order).
858 * Note that the byte order conversion macros may evaluate their arguments
859 * multiple times, thus you should not use them with arguments which have
860 * side-effects.
864 * G_BYTE_ORDER:
866 * The host byte order.
867 * This can be either #G_LITTLE_ENDIAN or #G_BIG_ENDIAN (support for
868 * #G_PDP_ENDIAN may be added in future.)
872 * G_LITTLE_ENDIAN:
874 * Specifies one of the possible types of byte order.
875 * See #G_BYTE_ORDER.
879 * G_BIG_ENDIAN:
881 * Specifies one of the possible types of byte order.
882 * See #G_BYTE_ORDER.
886 * G_PDP_ENDIAN:
888 * Specifies one of the possible types of byte order
889 * (currently unused). See #G_BYTE_ORDER.
893 * g_htonl:
894 * @val: a 32-bit integer value in host byte order
896 * Converts a 32-bit integer value from host to network byte order.
898 * Returns: @val converted to network byte order
902 * g_htons:
903 * @val: a 16-bit integer value in host byte order
905 * Converts a 16-bit integer value from host to network byte order.
907 * Returns: @val converted to network byte order
911 * g_ntohl:
912 * @val: a 32-bit integer value in network byte order
914 * Converts a 32-bit integer value from network to host byte order.
916 * Returns: @val converted to host byte order.
920 * g_ntohs:
921 * @val: a 16-bit integer value in network byte order
923 * Converts a 16-bit integer value from network to host byte order.
925 * Returns: @val converted to host byte order
929 * GINT_FROM_BE:
930 * @val: a #gint value in big-endian byte order
932 * Converts a #gint value from big-endian to host byte order.
934 * Returns: @val converted to host byte order
938 * GINT_FROM_LE:
939 * @val: a #gint value in little-endian byte order
941 * Converts a #gint value from little-endian to host byte order.
943 * Returns: @val converted to host byte order
947 * GINT_TO_BE:
948 * @val: a #gint value in host byte order
950 * Converts a #gint value from host byte order to big-endian.
952 * Returns: @val converted to big-endian byte order
956 * GINT_TO_LE:
957 * @val: a #gint value in host byte order
959 * Converts a #gint value from host byte order to little-endian.
961 * Returns: @val converted to little-endian byte order
965 * GUINT_FROM_BE:
966 * @val: a #guint value in big-endian byte order
968 * Converts a #guint value from big-endian to host byte order.
970 * Returns: @val converted to host byte order
974 * GUINT_FROM_LE:
975 * @val: a #guint value in little-endian byte order
977 * Converts a #guint value from little-endian to host byte order.
979 * Returns: @val converted to host byte order
983 * GUINT_TO_BE:
984 * @val: a #guint value in host byte order
986 * Converts a #guint value from host byte order to big-endian.
988 * Returns: @val converted to big-endian byte order
992 * GUINT_TO_LE:
993 * @val: a #guint value in host byte order
995 * Converts a #guint value from host byte order to little-endian.
997 * Returns: @val converted to little-endian byte order.
1001 * GLONG_FROM_BE:
1002 * @val: a #glong value in big-endian byte order
1004 * Converts a #glong value from big-endian to the host byte order.
1006 * Returns: @val converted to host byte order
1010 * GLONG_FROM_LE:
1011 * @val: a #glong value in little-endian byte order
1013 * Converts a #glong value from little-endian to host byte order.
1015 * Returns: @val converted to host byte order
1019 * GLONG_TO_BE:
1020 * @val: a #glong value in host byte order
1022 * Converts a #glong value from host byte order to big-endian.
1024 * Returns: @val converted to big-endian byte order
1028 * GLONG_TO_LE:
1029 * @val: a #glong value in host byte order
1031 * Converts a #glong value from host byte order to little-endian.
1033 * Returns: @val converted to little-endian
1037 * GULONG_FROM_BE:
1038 * @val: a #gulong value in big-endian byte order
1040 * Converts a #gulong value from big-endian to host byte order.
1042 * Returns: @val converted to host byte order
1046 * GULONG_FROM_LE:
1047 * @val: a #gulong value in little-endian byte order
1049 * Converts a #gulong value from little-endian to host byte order.
1051 * Returns: @val converted to host byte order
1055 * GULONG_TO_BE:
1056 * @val: a #gulong value in host byte order
1058 * Converts a #gulong value from host byte order to big-endian.
1060 * Returns: @val converted to big-endian
1064 * GULONG_TO_LE:
1065 * @val: a #gulong value in host byte order
1067 * Converts a #gulong value from host byte order to little-endian.
1069 * Returns: @val converted to little-endian
1073 * GSIZE_FROM_BE:
1074 * @val: a #gsize value in big-endian byte order
1076 * Converts a #gsize value from big-endian to the host byte order.
1078 * Returns: @val converted to host byte order
1082 * GSIZE_FROM_LE:
1083 * @val: a #gsize value in little-endian byte order
1085 * Converts a #gsize value from little-endian to host byte order.
1087 * Returns: @val converted to host byte order
1091 * GSIZE_TO_BE:
1092 * @val: a #gsize value in host byte order
1094 * Converts a #gsize value from host byte order to big-endian.
1096 * Returns: @val converted to big-endian byte order
1100 * GSIZE_TO_LE:
1101 * @val: a #gsize value in host byte order
1103 * Converts a #gsize value from host byte order to little-endian.
1105 * Returns: @val converted to little-endian
1109 * GSSIZE_FROM_BE:
1110 * @val: a #gssize value in big-endian byte order
1112 * Converts a #gssize value from big-endian to host byte order.
1114 * Returns: @val converted to host byte order
1118 * GSSIZE_FROM_LE:
1119 * @val: a #gssize value in little-endian byte order
1121 * Converts a #gssize value from little-endian to host byte order.
1123 * Returns: @val converted to host byte order
1127 * GSSIZE_TO_BE:
1128 * @val: a #gssize value in host byte order
1130 * Converts a #gssize value from host byte order to big-endian.
1132 * Returns: @val converted to big-endian
1136 * GSSIZE_TO_LE:
1137 * @val: a #gssize value in host byte order
1139 * Converts a #gssize value from host byte order to little-endian.
1141 * Returns: @val converted to little-endian
1145 * GINT16_FROM_BE:
1146 * @val: a #gint16 value in big-endian byte order
1148 * Converts a #gint16 value from big-endian to host byte order.
1150 * Returns: @val converted to host byte order
1154 * GINT16_FROM_LE:
1155 * @val: a #gint16 value in little-endian byte order
1157 * Converts a #gint16 value from little-endian to host byte order.
1159 * Returns: @val converted to host byte order
1163 * GINT16_TO_BE:
1164 * @val: a #gint16 value in host byte order
1166 * Converts a #gint16 value from host byte order to big-endian.
1168 * Returns: @val converted to big-endian
1172 * GINT16_TO_LE:
1173 * @val: a #gint16 value in host byte order
1175 * Converts a #gint16 value from host byte order to little-endian.
1177 * Returns: @val converted to little-endian
1181 * GUINT16_FROM_BE:
1182 * @val: a #guint16 value in big-endian byte order
1184 * Converts a #guint16 value from big-endian to host byte order.
1186 * Returns: @val converted to host byte order
1190 * GUINT16_FROM_LE:
1191 * @val: a #guint16 value in little-endian byte order
1193 * Converts a #guint16 value from little-endian to host byte order.
1195 * Returns: @val converted to host byte order
1199 * GUINT16_TO_BE:
1200 * @val: a #guint16 value in host byte order
1202 * Converts a #guint16 value from host byte order to big-endian.
1204 * Returns: @val converted to big-endian
1208 * GUINT16_TO_LE:
1209 * @val: a #guint16 value in host byte order
1211 * Converts a #guint16 value from host byte order to little-endian.
1213 * Returns: @val converted to little-endian
1217 * GINT32_FROM_BE:
1218 * @val: a #gint32 value in big-endian byte order
1220 * Converts a #gint32 value from big-endian to host byte order.
1222 * Returns: @val converted to host byte order
1226 * GINT32_FROM_LE:
1227 * @val: a #gint32 value in little-endian byte order
1229 * Converts a #gint32 value from little-endian to host byte order.
1231 * Returns: @val converted to host byte order
1235 * GINT32_TO_BE:
1236 * @val: a #gint32 value in host byte order
1238 * Converts a #gint32 value from host byte order to big-endian.
1240 * Returns: @val converted to big-endian
1244 * GINT32_TO_LE:
1245 * @val: a #gint32 value in host byte order
1247 * Converts a #gint32 value from host byte order to little-endian.
1249 * Returns: @val converted to little-endian
1253 * GUINT32_FROM_BE:
1254 * @val: a #guint32 value in big-endian byte order
1256 * Converts a #guint32 value from big-endian to host byte order.
1258 * Returns: @val converted to host byte order
1262 * GUINT32_FROM_LE:
1263 * @val: a #guint32 value in little-endian byte order
1265 * Converts a #guint32 value from little-endian to host byte order.
1267 * Returns: @val converted to host byte order
1271 * GUINT32_TO_BE:
1272 * @val: a #guint32 value in host byte order
1274 * Converts a #guint32 value from host byte order to big-endian.
1276 * Returns: @val converted to big-endian
1280 * GUINT32_TO_LE:
1281 * @val: a #guint32 value in host byte order
1283 * Converts a #guint32 value from host byte order to little-endian.
1285 * Returns: @val converted to little-endian
1289 * GINT64_FROM_BE:
1290 * @val: a #gint64 value in big-endian byte order
1292 * Converts a #gint64 value from big-endian to host byte order.
1294 * Returns: @val converted to host byte order
1298 * GINT64_FROM_LE:
1299 * @val: a #gint64 value in little-endian byte order
1301 * Converts a #gint64 value from little-endian to host byte order.
1303 * Returns: @val converted to host byte order
1307 * GINT64_TO_BE:
1308 * @val: a #gint64 value in host byte order
1310 * Converts a #gint64 value from host byte order to big-endian.
1312 * Returns: @val converted to big-endian
1316 * GINT64_TO_LE:
1317 * @val: a #gint64 value in host byte order
1319 * Converts a #gint64 value from host byte order to little-endian.
1321 * Returns: @val converted to little-endian
1325 * GUINT64_FROM_BE:
1326 * @val: a #guint64 value in big-endian byte order
1328 * Converts a #guint64 value from big-endian to host byte order.
1330 * Returns: @val converted to host byte order
1334 * GUINT64_FROM_LE:
1335 * @val: a #guint64 value in little-endian byte order
1337 * Converts a #guint64 value from little-endian to host byte order.
1339 * Returns: @val converted to host byte order
1343 * GUINT64_TO_BE:
1344 * @val: a #guint64 value in host byte order
1346 * Converts a #guint64 value from host byte order to big-endian.
1348 * Returns: @val converted to big-endian
1352 * GUINT64_TO_LE:
1353 * @val: a #guint64 value in host byte order
1355 * Converts a #guint64 value from host byte order to little-endian.
1357 * Returns: @val converted to little-endian
1361 * GUINT16_SWAP_BE_PDP:
1362 * @val: a #guint16 value in big-endian or pdp-endian byte order
1364 * Converts a #guint16 value between big-endian and pdp-endian byte order.
1365 * The conversion is symmetric so it can be used both ways.
1367 * Returns: @val converted to the opposite byte order
1371 * GUINT16_SWAP_LE_BE:
1372 * @val: a #guint16 value in little-endian or big-endian byte order
1374 * Converts a #guint16 value between little-endian and big-endian byte order.
1375 * The conversion is symmetric so it can be used both ways.
1377 * Returns: @val converted to the opposite byte order
1381 * GUINT16_SWAP_LE_PDP:
1382 * @val: a #guint16 value in little-endian or pdp-endian byte order
1384 * Converts a #guint16 value between little-endian and pdp-endian byte order.
1385 * The conversion is symmetric so it can be used both ways.
1387 * Returns: @val converted to the opposite byte order
1391 * GUINT32_SWAP_BE_PDP:
1392 * @val: a #guint32 value in big-endian or pdp-endian byte order
1394 * Converts a #guint32 value between big-endian and pdp-endian byte order.
1395 * The conversion is symmetric so it can be used both ways.
1397 * Returns: @val converted to the opposite byte order
1401 * GUINT32_SWAP_LE_BE:
1402 * @val: a #guint32 value in little-endian or big-endian byte order
1404 * Converts a #guint32 value between little-endian and big-endian byte order.
1405 * The conversion is symmetric so it can be used both ways.
1407 * Returns: @val converted to the opposite byte order
1411 * GUINT32_SWAP_LE_PDP:
1412 * @val: a #guint32 value in little-endian or pdp-endian byte order
1414 * Converts a #guint32 value between little-endian and pdp-endian byte order.
1415 * The conversion is symmetric so it can be used both ways.
1417 * Returns: @val converted to the opposite byte order
1421 * GUINT64_SWAP_LE_BE:
1422 * @val: a #guint64 value in little-endian or big-endian byte order
1424 * Converts a #guint64 value between little-endian and big-endian byte order.
1425 * The conversion is symmetric so it can be used both ways.
1427 * Returns: @val converted to the opposite byte order
1430 /* Bounds-checked integer arithmetic {{{1 */
1432 * SECTION:checkedmath
1433 * @title: Bounds-checking integer arithmetic
1434 * @short_description: a set of helpers for performing checked integer arithmetic
1436 * GLib offers a set of macros for doing additions and multiplications
1437 * of unsigned integers, with checks for overflows.
1439 * The helpers all have three arguments. A pointer to the destination
1440 * is always the first argument and the operands to the operation are
1441 * the other two.
1443 * Following standard GLib convention, the helpers return %TRUE in case
1444 * of success (ie: no overflow).
1446 * The helpers may be macros, normal functions or inlines. They may be
1447 * implemented with inline assembly or compiler intrinsics where
1448 * available.
1450 * Since: 2.48
1454 * g_uint_checked_add
1455 * @dest: a pointer to the #guint destination
1456 * @a: the #guint left operand
1457 * @b: the #guint right operand
1459 * Performs a checked addition of @a and @b, storing the result in
1460 * @dest.
1462 * If the operation is successful, %TRUE is returned. If the operation
1463 * overflows then the state of @dest is undefined and %FALSE is
1464 * returned.
1466 * Returns: %TRUE if there was no overflow
1467 * Since: 2.48
1471 * g_uint_checked_mul
1472 * @dest: a pointer to the #guint destination
1473 * @a: the #guint left operand
1474 * @b: the #guint right operand
1476 * Performs a checked multiplication of @a and @b, storing the result in
1477 * @dest.
1479 * If the operation is successful, %TRUE is returned. If the operation
1480 * overflows then the state of @dest is undefined and %FALSE is
1481 * returned.
1483 * Returns: %TRUE if there was no overflow
1484 * Since: 2.48
1488 * g_uint64_checked_add
1489 * @dest: a pointer to the #guint64 destination
1490 * @a: the #guint64 left operand
1491 * @b: the #guint64 right operand
1493 * Performs a checked addition of @a and @b, storing the result in
1494 * @dest.
1496 * If the operation is successful, %TRUE is returned. If the operation
1497 * overflows then the state of @dest is undefined and %FALSE is
1498 * returned.
1500 * Returns: %TRUE if there was no overflow
1501 * Since: 2.48
1505 * g_uint64_checked_mul
1506 * @dest: a pointer to the #guint64 destination
1507 * @a: the #guint64 left operand
1508 * @b: the #guint64 right operand
1510 * Performs a checked multiplication of @a and @b, storing the result in
1511 * @dest.
1513 * If the operation is successful, %TRUE is returned. If the operation
1514 * overflows then the state of @dest is undefined and %FALSE is
1515 * returned.
1517 * Returns: %TRUE if there was no overflow
1518 * Since: 2.48
1522 * g_size_checked_add
1523 * @dest: a pointer to the #gsize destination
1524 * @a: the #gsize left operand
1525 * @b: the #gsize right operand
1527 * Performs a checked addition of @a and @b, storing the result in
1528 * @dest.
1530 * If the operation is successful, %TRUE is returned. If the operation
1531 * overflows then the state of @dest is undefined and %FALSE is
1532 * returned.
1534 * Returns: %TRUE if there was no overflow
1535 * Since: 2.48
1539 * g_size_checked_mul
1540 * @dest: a pointer to the #gsize destination
1541 * @a: the #gsize left operand
1542 * @b: the #gsize right operand
1544 * Performs a checked multiplication of @a and @b, storing the result in
1545 * @dest.
1547 * If the operation is successful, %TRUE is returned. If the operation
1548 * overflows then the state of @dest is undefined and %FALSE is
1549 * returned.
1551 * Returns: %TRUE if there was no overflow
1552 * Since: 2.48
1554 /* Numerical Definitions {{{1 */
1557 * SECTION:numerical
1558 * @title: Numerical Definitions
1559 * @short_description: mathematical constants, and floating point decomposition
1561 * GLib offers mathematical constants such as #G_PI for the value of pi;
1562 * many platforms have these in the C library, but some don't, the GLib
1563 * versions always exist.
1565 * The #GFloatIEEE754 and #GDoubleIEEE754 unions are used to access the
1566 * sign, mantissa and exponent of IEEE floats and doubles. These unions are
1567 * defined as appropriate for a given platform. IEEE floats and doubles are
1568 * supported (used for storage) by at least Intel, PPC and Sparc. See
1569 * [IEEE 754-2008](http://en.wikipedia.org/wiki/IEEE_float)
1570 * for more information about IEEE number formats.
1574 * G_IEEE754_FLOAT_BIAS:
1576 * The bias by which exponents in single-precision floats are offset.
1580 * G_IEEE754_DOUBLE_BIAS:
1582 * The bias by which exponents in double-precision floats are offset.
1586 * GFloatIEEE754:
1587 * @v_float: the double value
1589 * The #GFloatIEEE754 and #GDoubleIEEE754 unions are used to access the sign,
1590 * mantissa and exponent of IEEE floats and doubles. These unions are defined
1591 * as appropriate for a given platform. IEEE floats and doubles are supported
1592 * (used for storage) by at least Intel, PPC and Sparc.
1596 * GDoubleIEEE754:
1597 * @v_double: the double value
1599 * The #GFloatIEEE754 and #GDoubleIEEE754 unions are used to access the sign,
1600 * mantissa and exponent of IEEE floats and doubles. These unions are defined
1601 * as appropriate for a given platform. IEEE floats and doubles are supported
1602 * (used for storage) by at least Intel, PPC and Sparc.
1606 * G_E:
1608 * The base of natural logarithms.
1612 * G_LN2:
1614 * The natural logarithm of 2.
1618 * G_LN10:
1620 * The natural logarithm of 10.
1624 * G_PI:
1626 * The value of pi (ratio of circle's circumference to its diameter).
1630 * G_PI_2:
1632 * Pi divided by 2.
1636 * G_PI_4:
1638 * Pi divided by 4.
1642 * G_SQRT2:
1644 * The square root of two.
1648 * G_LOG_2_BASE_10:
1650 * Multiplying the base 2 exponent by this number yields the base 10 exponent.
1653 /* Macros {{{1 */
1656 * SECTION:macros
1657 * @title: Standard Macros
1658 * @short_description: commonly-used macros
1660 * These macros provide a few commonly-used features.
1664 * G_OS_WIN32:
1666 * This macro is defined only on Windows. So you can bracket
1667 * Windows-specific code in "\#ifdef G_OS_WIN32".
1671 * G_OS_UNIX:
1673 * This macro is defined only on UNIX. So you can bracket
1674 * UNIX-specific code in "\#ifdef G_OS_UNIX".
1678 * G_DIR_SEPARATOR:
1680 * The directory separator character.
1681 * This is '/' on UNIX machines and '\' under Windows.
1685 * G_DIR_SEPARATOR_S:
1687 * The directory separator as a string.
1688 * This is "/" on UNIX machines and "\" under Windows.
1692 * G_IS_DIR_SEPARATOR:
1693 * @c: a character
1695 * Checks whether a character is a directory
1696 * separator. It returns %TRUE for '/' on UNIX
1697 * machines and for '\' or '/' under Windows.
1699 * Since: 2.6
1703 * G_SEARCHPATH_SEPARATOR:
1705 * The search path separator character.
1706 * This is ':' on UNIX machines and ';' under Windows.
1710 * G_SEARCHPATH_SEPARATOR_S:
1712 * The search path separator as a string.
1713 * This is ":" on UNIX machines and ";" under Windows.
1717 * TRUE:
1719 * Defines the %TRUE value for the #gboolean type.
1723 * FALSE:
1725 * Defines the %FALSE value for the #gboolean type.
1729 * NULL:
1731 * Defines the standard %NULL pointer.
1735 * MIN:
1736 * @a: a numeric value
1737 * @b: a numeric value
1739 * Calculates the minimum of @a and @b.
1741 * Returns: the minimum of @a and @b.
1745 * MAX:
1746 * @a: a numeric value
1747 * @b: a numeric value
1749 * Calculates the maximum of @a and @b.
1751 * Returns: the maximum of @a and @b.
1755 * ABS:
1756 * @a: a numeric value
1758 * Calculates the absolute value of @a.
1759 * The absolute value is simply the number with any negative sign taken away.
1761 * For example,
1762 * - ABS(-10) is 10.
1763 * - ABS(10) is also 10.
1765 * Returns: the absolute value of @a.
1769 * CLAMP:
1770 * @x: the value to clamp
1771 * @low: the minimum value allowed
1772 * @high: the maximum value allowed
1774 * Ensures that @x is between the limits set by @low and @high. If @low is
1775 * greater than @high the result is undefined.
1777 * For example,
1778 * - CLAMP(5, 10, 15) is 10.
1779 * - CLAMP(15, 5, 10) is 10.
1780 * - CLAMP(20, 15, 25) is 20.
1782 * Returns: the value of @x clamped to the range between @low and @high
1786 * G_STRUCT_MEMBER:
1787 * @member_type: the type of the struct field
1788 * @struct_p: a pointer to a struct
1789 * @struct_offset: the offset of the field from the start of the struct,
1790 * in bytes
1792 * Returns a member of a structure at a given offset, using the given type.
1794 * Returns: the struct member
1798 * G_STRUCT_MEMBER_P:
1799 * @struct_p: a pointer to a struct
1800 * @struct_offset: the offset from the start of the struct, in bytes
1802 * Returns an untyped pointer to a given offset of a struct.
1804 * Returns: an untyped pointer to @struct_p plus @struct_offset bytes
1808 * G_STRUCT_OFFSET:
1809 * @struct_type: a structure type, e.g. #GtkWidget
1810 * @member: a field in the structure, e.g. @window
1812 * Returns the offset, in bytes, of a member of a struct.
1814 * Returns: the offset of @member from the start of @struct_type
1818 * G_CONST_RETURN:
1820 * If %G_DISABLE_CONST_RETURNS is defined, this macro expands
1821 * to nothing. By default, the macro expands to const. The macro
1822 * can be used in place of const for functions that return a value
1823 * that should not be modified. The purpose of this macro is to allow
1824 * us to turn on const for returned constant strings by default, while
1825 * allowing programmers who find that annoying to turn it off. This macro
1826 * should only be used for return values and for "out" parameters, it
1827 * doesn't make sense for "in" parameters.
1829 * Deprecated: 2.30: API providers should replace all existing uses with
1830 * const and API consumers should adjust their code accordingly
1834 * G_N_ELEMENTS:
1835 * @arr: the array
1837 * Determines the number of elements in an array. The array must be
1838 * declared so the compiler knows its size at compile-time; this
1839 * macro will not work on an array allocated on the heap, only static
1840 * arrays or arrays on the stack.
1843 /* Miscellaneous Macros {{{1 */
1846 * SECTION:macros_misc
1847 * @title: Miscellaneous Macros
1848 * @short_description: specialized macros which are not used often
1850 * These macros provide more specialized features which are not
1851 * needed so often by application programmers.
1855 * G_INLINE_FUNC:
1857 * This macro used to be used to conditionally define inline functions
1858 * in a compatible way before this feature was supported in all
1859 * compilers. These days, GLib requires inlining support from the
1860 * compiler, so your GLib-using programs can safely assume that the
1861 * "inline" keywork works properly.
1863 * Never use this macro anymore. Just say "static inline".
1865 * Deprecated: 2.48: Use "static inline" instead
1869 * G_STMT_START:
1871 * Used within multi-statement macros so that they can be used in places
1872 * where only one statement is expected by the compiler.
1876 * G_STMT_END:
1878 * Used within multi-statement macros so that they can be used in places
1879 * where only one statement is expected by the compiler.
1883 * G_BEGIN_DECLS:
1885 * Used (along with #G_END_DECLS) to bracket header files. If the
1886 * compiler in use is a C++ compiler, adds extern "C"
1887 * around the header.
1891 * G_END_DECLS:
1893 * Used (along with #G_BEGIN_DECLS) to bracket header files. If the
1894 * compiler in use is a C++ compiler, adds extern "C"
1895 * around the header.
1899 * G_VA_COPY:
1900 * @ap1: the va_list variable to place a copy of @ap2 in
1901 * @ap2: a va_list
1903 * Portable way to copy va_list variables.
1905 * In order to use this function, you must include string.h yourself,
1906 * because this macro may use memmove() and GLib does not include
1907 * string.h for you.
1911 * G_STRINGIFY:
1912 * @macro_or_string: a macro or a string
1914 * Accepts a macro or a string and converts it into a string after
1915 * preprocessor argument expansion. For example, the following code:
1917 * |[<!-- language="C" -->
1918 * #define AGE 27
1919 * const gchar *greeting = G_STRINGIFY (AGE) " today!";
1920 * ]|
1922 * is transformed by the preprocessor into (code equivalent to):
1924 * |[<!-- language="C" -->
1925 * const gchar *greeting = "27 today!";
1926 * ]|
1930 * G_PASTE:
1931 * @identifier1: an identifier
1932 * @identifier2: an identifier
1934 * Yields a new preprocessor pasted identifier
1935 * @identifier1identifier2 from its expanded
1936 * arguments @identifier1 and @identifier2. For example,
1937 * the following code:
1938 * |[<!-- language="C" -->
1939 * #define GET(traveller,method) G_PASTE(traveller_get_, method) (traveller)
1940 * const gchar *name = GET (traveller, name);
1941 * const gchar *quest = GET (traveller, quest);
1942 * GdkColor *favourite = GET (traveller, favourite_colour);
1943 * ]|
1945 * is transformed by the preprocessor into:
1946 * |[<!-- language="C" -->
1947 * const gchar *name = traveller_get_name (traveller);
1948 * const gchar *quest = traveller_get_quest (traveller);
1949 * GdkColor *favourite = traveller_get_favourite_colour (traveller);
1950 * ]|
1952 * Since: 2.20
1956 * G_STATIC_ASSERT:
1957 * @expr: a constant expression
1959 * The G_STATIC_ASSERT() macro lets the programmer check
1960 * a condition at compile time, the condition needs to
1961 * be compile time computable. The macro can be used in
1962 * any place where a typedef is valid.
1964 * A typedef is generally allowed in exactly the same places that
1965 * a variable declaration is allowed. For this reason, you should
1966 * not use G_STATIC_ASSERT() in the middle of blocks of code.
1968 * The macro should only be used once per source code line.
1970 * Since: 2.20
1974 * G_STATIC_ASSERT_EXPR:
1975 * @expr: a constant expression
1977 * The G_STATIC_ASSERT_EXPR() macro lets the programmer check
1978 * a condition at compile time. The condition needs to be
1979 * compile time computable.
1981 * Unlike G_STATIC_ASSERT(), this macro evaluates to an expression
1982 * and, as such, can be used in the middle of other expressions.
1983 * Its value should be ignored. This can be accomplished by placing
1984 * it as the first argument of a comma expression.
1986 * |[<!-- language="C" -->
1987 * #define ADD_ONE_TO_INT(x) \
1988 * (G_STATIC_ASSERT_EXPR(sizeof (x) == sizeof (int)), ((x) + 1))
1989 * ]|
1991 * Since: 2.30
1995 * G_GNUC_EXTENSION:
1997 * Expands to __extension__ when gcc is used as the compiler. This simply
1998 * tells gcc not to warn about the following non-standard code when compiling
1999 * with the `-pedantic` option.
2003 * G_GNUC_CHECK_VERSION:
2004 * @major: major version to check against
2005 * @minor: minor version to check against
2007 * Expands to a a check for a compiler with __GNUC__ defined and a version
2008 * greater than or equal to the major and minor numbers provided. For example,
2009 * the following would only match on compilers such as GCC 4.8 or newer.
2011 * |[<!-- language="C" -->
2012 * #if G_GNUC_CHECK_VERSION(4, 8)
2013 * #endif
2014 * ]|
2016 * Since: 2.42
2020 * G_GNUC_CONST:
2022 * Expands to the GNU C const function attribute if the compiler is gcc.
2023 * Declaring a function as const enables better optimization of calls to
2024 * the function. A const function doesn't examine any values except its
2025 * parameters, and has no effects except its return value.
2027 * Place the attribute after the declaration, just before the semicolon.
2029 * See the GNU C documentation for more details.
2031 * A function that has pointer arguments and examines the data pointed to
2032 * must not be declared const. Likewise, a function that calls a non-const
2033 * function usually must not be const. It doesn't make sense for a const
2034 * function to return void.
2038 * G_GNUC_PURE:
2040 * Expands to the GNU C pure function attribute if the compiler is gcc.
2041 * Declaring a function as pure enables better optimization of calls to
2042 * the function. A pure function has no effects except its return value
2043 * and the return value depends only on the parameters and/or global
2044 * variables.
2046 * Place the attribute after the declaration, just before the semicolon.
2048 * See the GNU C documentation for more details.
2052 * G_GNUC_MALLOC:
2054 * Expands to the GNU C malloc function attribute if the compiler is gcc.
2055 * Declaring a function as malloc enables better optimization of the function.
2056 * A function can have the malloc attribute if it returns a pointer which is
2057 * guaranteed to not alias with any other pointer when the function returns
2058 * (in practice, this means newly allocated memory).
2060 * Place the attribute after the declaration, just before the semicolon.
2062 * See the GNU C documentation for more details.
2064 * Since: 2.6
2068 * G_GNUC_ALLOC_SIZE:
2069 * @x: the index of the argument specifying the allocation size
2071 * Expands to the GNU C alloc_size function attribute if the compiler
2072 * is a new enough gcc. This attribute tells the compiler that the
2073 * function returns a pointer to memory of a size that is specified
2074 * by the @xth function parameter.
2076 * Place the attribute after the function declaration, just before the
2077 * semicolon.
2079 * See the GNU C documentation for more details.
2081 * Since: 2.18
2085 * G_GNUC_ALLOC_SIZE2:
2086 * @x: the index of the argument specifying one factor of the allocation size
2087 * @y: the index of the argument specifying the second factor of the allocation size
2089 * Expands to the GNU C alloc_size function attribute if the compiler is a
2090 * new enough gcc. This attribute tells the compiler that the function returns
2091 * a pointer to memory of a size that is specified by the product of two
2092 * function parameters.
2094 * Place the attribute after the function declaration, just before the
2095 * semicolon.
2097 * See the GNU C documentation for more details.
2099 * Since: 2.18
2103 * G_GNUC_DEPRECATED:
2105 * Expands to the GNU C deprecated attribute if the compiler is gcc.
2106 * It can be used to mark typedefs, variables and functions as deprecated.
2107 * When called with the `-Wdeprecated-declarations` option,
2108 * gcc will generate warnings when deprecated interfaces are used.
2110 * Place the attribute after the declaration, just before the semicolon.
2112 * See the GNU C documentation for more details.
2114 * Since: 2.2
2118 * G_GNUC_DEPRECATED_FOR:
2119 * @f: the intended replacement for the deprecated symbol,
2120 * such as the name of a function
2122 * Like %G_GNUC_DEPRECATED, but names the intended replacement for the
2123 * deprecated symbol if the version of gcc in use is new enough to support
2124 * custom deprecation messages.
2126 * Place the attribute after the declaration, just before the semicolon.
2128 * See the GNU C documentation for more details.
2130 * Note that if @f is a macro, it will be expanded in the warning message.
2131 * You can enclose it in quotes to prevent this. (The quotes will show up
2132 * in the warning, but it's better than showing the macro expansion.)
2134 * Since: 2.26
2138 * G_GNUC_BEGIN_IGNORE_DEPRECATIONS:
2140 * Tells gcc (if it is a new enough version) to temporarily stop emitting
2141 * warnings when functions marked with %G_GNUC_DEPRECATED or
2142 * %G_GNUC_DEPRECATED_FOR are called. This is useful for when you have
2143 * one deprecated function calling another one, or when you still have
2144 * regression tests for deprecated functions.
2146 * Use %G_GNUC_END_IGNORE_DEPRECATIONS to begin warning again. (If you
2147 * are not compiling with `-Wdeprecated-declarations` then neither macro
2148 * has any effect.)
2150 * This macro can be used either inside or outside of a function body,
2151 * but must appear on a line by itself.
2153 * Since: 2.32
2157 * G_GNUC_END_IGNORE_DEPRECATIONS:
2159 * Undoes the effect of %G_GNUC_BEGIN_IGNORE_DEPRECATIONS, telling
2160 * gcc to begin outputting warnings again (assuming those warnings
2161 * had been enabled to begin with).
2163 * This macro can be used either inside or outside of a function body,
2164 * but must appear on a line by itself.
2166 * Since: 2.32
2170 * G_DEPRECATED:
2172 * This macro is similar to %G_GNUC_DEPRECATED, and can be used to mark
2173 * functions declarations as deprecated. Unlike %G_GNUC_DEPRECATED, it is
2174 * meant to be portable across different compilers and must be placed
2175 * before the function declaration.
2177 * Since: 2.32
2181 * G_DEPRECATED_FOR:
2182 * @f: the name of the function that this function was deprecated for
2184 * This macro is similar to %G_GNUC_DEPRECATED_FOR, and can be used to mark
2185 * functions declarations as deprecated. Unlike %G_GNUC_DEPRECATED_FOR, it
2186 * is meant to be portable across different compilers and must be placed
2187 * before the function declaration.
2189 * Since: 2.32
2193 * G_UNAVAILABLE:
2194 * @maj: the major version that introduced the symbol
2195 * @min: the minor version that introduced the symbol
2197 * This macro can be used to mark a function declaration as unavailable.
2198 * It must be placed before the function declaration. Use of a function
2199 * that has been annotated with this macros will produce a compiler warning.
2201 * Since: 2.32
2205 * GLIB_DISABLE_DEPRECATION_WARNINGS:
2207 * A macro that should be defined before including the glib.h header.
2208 * If it is defined, no compiler warnings will be produced for uses
2209 * of deprecated GLib APIs.
2213 * G_GNUC_NORETURN:
2215 * Expands to the GNU C noreturn function attribute if the compiler is gcc.
2216 * It is used for declaring functions which never return. It enables
2217 * optimization of the function, and avoids possible compiler warnings.
2219 * Place the attribute after the declaration, just before the semicolon.
2221 * See the GNU C documentation for more details.
2225 * G_GNUC_UNUSED:
2227 * Expands to the GNU C unused function attribute if the compiler is gcc.
2228 * It is used for declaring functions and arguments which may never be used.
2229 * It avoids possible compiler warnings.
2231 * For functions, place the attribute after the declaration, just before the
2232 * semicolon. For arguments, place the attribute at the beginning of the
2233 * argument declaration.
2235 * |[<!-- language="C" -->
2236 * void my_unused_function (G_GNUC_UNUSED gint unused_argument,
2237 * gint other_argument) G_GNUC_UNUSED;
2238 * ]|
2240 * See the GNU C documentation for more details.
2244 * G_GNUC_PRINTF:
2245 * @format_idx: the index of the argument corresponding to the
2246 * format string (the arguments are numbered from 1)
2247 * @arg_idx: the index of the first of the format arguments, or 0 if
2248 * there are no format arguments
2250 * Expands to the GNU C format function attribute if the compiler is gcc.
2251 * This is used for declaring functions which take a variable number of
2252 * arguments, with the same syntax as printf(). It allows the compiler
2253 * to type-check the arguments passed to the function.
2255 * Place the attribute after the function declaration, just before the
2256 * semicolon.
2258 * See the
2259 * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-3288)
2260 * for more details.
2262 * |[<!-- language="C" -->
2263 * gint g_snprintf (gchar *string,
2264 * gulong n,
2265 * gchar const *format,
2266 * ...) G_GNUC_PRINTF (3, 4);
2267 * ]|
2271 * G_GNUC_SCANF:
2272 * @format_idx: the index of the argument corresponding to
2273 * the format string (the arguments are numbered from 1)
2274 * @arg_idx: the index of the first of the format arguments, or 0 if
2275 * there are no format arguments
2277 * Expands to the GNU C format function attribute if the compiler is gcc.
2278 * This is used for declaring functions which take a variable number of
2279 * arguments, with the same syntax as scanf(). It allows the compiler
2280 * to type-check the arguments passed to the function.
2282 * See the
2283 * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-3288)
2284 * for details.
2288 * G_GNUC_FORMAT:
2289 * @arg_idx: the index of the argument
2291 * Expands to the GNU C format_arg function attribute if the compiler
2292 * is gcc. This function attribute specifies that a function takes a
2293 * format string for a printf(), scanf(), strftime() or strfmon() style
2294 * function and modifies it, so that the result can be passed to a printf(),
2295 * scanf(), strftime() or strfmon() style function (with the remaining
2296 * arguments to the format function the same as they would have been
2297 * for the unmodified string).
2299 * Place the attribute after the function declaration, just before the
2300 * semicolon.
2302 * See the GNU C documentation for more details.
2304 * |[<!-- language="C" -->
2305 * gchar *g_dgettext (gchar *domain_name, gchar *msgid) G_GNUC_FORMAT (2);
2306 * ]|
2310 * G_GNUC_NULL_TERMINATED:
2312 * Expands to the GNU C sentinel function attribute if the compiler is gcc.
2313 * This function attribute only applies to variadic functions and instructs
2314 * the compiler to check that the argument list is terminated with an
2315 * explicit %NULL.
2317 * Place the attribute after the declaration, just before the semicolon.
2319 * See the GNU C documentation for more details.
2321 * Since: 2.8
2325 * G_GNUC_WARN_UNUSED_RESULT:
2327 * Expands to the GNU C warn_unused_result function attribute if the compiler
2328 * is gcc. This function attribute makes the compiler emit a warning if the
2329 * result of a function call is ignored.
2331 * Place the attribute after the declaration, just before the semicolon.
2333 * See the GNU C documentation for more details.
2335 * Since: 2.10
2339 * G_GNUC_FUNCTION:
2341 * Expands to "" on all modern compilers, and to __FUNCTION__ on gcc
2342 * version 2.x. Don't use it.
2344 * Deprecated: 2.16: Use G_STRFUNC() instead
2348 * G_GNUC_PRETTY_FUNCTION:
2350 * Expands to "" on all modern compilers, and to __PRETTY_FUNCTION__
2351 * on gcc version 2.x. Don't use it.
2353 * Deprecated: 2.16: Use G_STRFUNC() instead
2357 * G_GNUC_NO_INSTRUMENT:
2359 * Expands to the GNU C no_instrument_function function attribute if the
2360 * compiler is gcc. Functions with this attribute will not be instrumented
2361 * for profiling, when the compiler is called with the
2362 * `-finstrument-functions` option.
2364 * Place the attribute after the declaration, just before the semicolon.
2366 * See the GNU C documentation for more details.
2370 * G_GNUC_INTERNAL:
2372 * This attribute can be used for marking library functions as being used
2373 * internally to the library only, which may allow the compiler to handle
2374 * function calls more efficiently. Note that static functions do not need
2375 * to be marked as internal in this way. See the GNU C documentation for
2376 * details.
2378 * When using a compiler that supports the GNU C hidden visibility attribute,
2379 * this macro expands to __attribute__((visibility("hidden"))).
2380 * When using the Sun Studio compiler, it expands to __hidden.
2382 * Note that for portability, the attribute should be placed before the
2383 * function declaration. While GCC allows the macro after the declaration,
2384 * Sun Studio does not.
2386 * |[<!-- language="C" -->
2387 * G_GNUC_INTERNAL
2388 * void _g_log_fallback_handler (const gchar *log_domain,
2389 * GLogLevelFlags log_level,
2390 * const gchar *message,
2391 * gpointer unused_data);
2392 * ]|
2394 * Since: 2.6
2398 * G_GNUC_MAY_ALIAS:
2400 * Expands to the GNU C may_alias type attribute if the compiler is gcc.
2401 * Types with this attribute will not be subjected to type-based alias
2402 * analysis, but are assumed to alias with any other type, just like char.
2404 * See the GNU C documentation for details.
2406 * Since: 2.14
2410 * G_LIKELY:
2411 * @expr: the expression
2413 * Hints the compiler that the expression is likely to evaluate to
2414 * a true value. The compiler may use this information for optimizations.
2416 * |[<!-- language="C" -->
2417 * if (G_LIKELY (random () != 1))
2418 * g_print ("not one");
2419 * ]|
2421 * Returns: the value of @expr
2423 * Since: 2.2
2427 * G_UNLIKELY:
2428 * @expr: the expression
2430 * Hints the compiler that the expression is unlikely to evaluate to
2431 * a true value. The compiler may use this information for optimizations.
2433 * |[<!-- language="C" -->
2434 * if (G_UNLIKELY (random () == 1))
2435 * g_print ("a random one");
2436 * ]|
2438 * Returns: the value of @expr
2440 * Since: 2.2
2444 * G_STRLOC:
2446 * Expands to a string identifying the current code position.
2450 * G_STRFUNC:
2452 * Expands to a string identifying the current function.
2454 * Since: 2.4
2458 * G_HAVE_GNUC_VISIBILITY:
2460 * Defined to 1 if gcc-style visibility handling is supported.
2463 /* g_auto(), g_autoptr() and helpers {{{1 */
2466 * g_auto:
2467 * @TypeName: a supported variable type
2469 * Helper to declare a variable with automatic cleanup.
2471 * The variable is cleaned up in a way appropriate to its type when the
2472 * variable goes out of scope. The type must support this.
2474 * This feature is only supported on GCC and clang. This macro is not
2475 * defined on other compilers and should not be used in programs that
2476 * are intended to be portable to those compilers.
2478 * This is meant to be used with stack-allocated structures and
2479 * non-pointer types. For the (more commonly used) pointer version, see
2480 * g_autoptr().
2482 * This macro can be used to avoid having to do explicit cleanups of
2483 * local variables when exiting functions. It often vastly simplifies
2484 * handling of error conditions, removing the need for various tricks
2485 * such as 'goto out' or repeating of cleanup code. It is also helpful
2486 * for non-error cases.
2488 * Consider the following example:
2490 * |[
2491 * GVariant *
2492 * my_func(void)
2494 * g_auto(GQueue) queue = G_QUEUE_INIT;
2495 * g_auto(GVariantBuilder) builder;
2496 * g_auto(GStrv) strv;
2498 * g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
2499 * strv = g_strsplit("a:b:c", ":", -1);
2501 * ...
2503 * if (error_condition)
2504 * return NULL;
2506 * ...
2508 * return g_variant_builder_end (&builder);
2510 * ]|
2512 * You must initialize the variable in some way -- either by use of an
2513 * initialiser or by ensuring that an _init function will be called on
2514 * it unconditionally before it goes out of scope.
2516 * Since: 2.44
2520 * g_autoptr:
2521 * @TypeName: a supported variable type
2523 * Helper to declare a pointer variable with automatic cleanup.
2525 * The variable is cleaned up in a way appropriate to its type when the
2526 * variable goes out of scope. The type must support this.
2528 * This feature is only supported on GCC and clang. This macro is not
2529 * defined on other compilers and should not be used in programs that
2530 * are intended to be portable to those compilers.
2532 * This is meant to be used to declare pointers to types with cleanup
2533 * functions. The type of the variable is a pointer to @TypeName. You
2534 * must not add your own '*'.
2536 * This macro can be used to avoid having to do explicit cleanups of
2537 * local variables when exiting functions. It often vastly simplifies
2538 * handling of error conditions, removing the need for various tricks
2539 * such as 'goto out' or repeating of cleanup code. It is also helpful
2540 * for non-error cases.
2542 * Consider the following example:
2544 * |[
2545 * gboolean
2546 * check_exists(GVariant *dict)
2548 * g_autoptr(GVariant) dirname, basename = NULL;
2549 * g_autofree gchar *path = NULL;
2551 * dirname = g_variant_lookup_value (dict, "dirname", G_VARIANT_TYPE_STRING);
2553 * if (dirname == NULL)
2554 * return FALSE;
2556 * basename = g_variant_lookup_value (dict, "basename", G_VARIANT_TYPE_STRING);
2558 * if (basename == NULL)
2559 * return FALSE;
2561 * path = g_build_filename (g_variant_get_string (dirname, NULL),
2562 * g_variant_get_string (basename, NULL),
2563 * NULL);
2565 * return g_access (path, R_OK) == 0;
2567 * ]|
2569 * You must initialise the variable in some way -- either by use of an
2570 * initialiser or by ensuring that it is assigned to unconditionally
2571 * before it goes out of scope.
2573 * See also g_auto(), g_autofree() and g_steal_pointer().
2575 * Since: 2.44
2579 * g_autofree:
2581 * Macro to add an attribute to pointer variable to ensure automatic
2582 * cleanup using g_free().
2584 * This macro differs from g_autoptr() in that it is an attribute supplied
2585 * before the type name, rather than wrapping the type definition. Instead
2586 * of using a type-specific lookup, this macro always calls g_free() directly.
2588 * This means it's useful for any type that is returned from
2589 * g_malloc().
2591 * Otherwise, this macro has similar constraints as g_autoptr() - only
2592 * supported on GCC and clang, the variable must be initialized, etc.
2594 * |[
2595 * gboolean
2596 * operate_on_malloc_buf (void)
2598 * g_autofree guint8* membuf = NULL;
2600 * membuf = g_malloc (8192);
2602 * // Some computation on membuf
2604 * // membuf will be automatically freed here
2605 * return TRUE;
2607 * ]|
2609 * Since: 2.44
2613 * g_autolist:
2614 * @TypeName: a supported variable type
2616 * Helper to declare a list variable with automatic deep cleanup.
2618 * The list is deeply freed, in a way appropriate to the specified type, when the
2619 * variable goes out of scope. The type must support this.
2621 * This feature is only supported on GCC and clang. This macro is not
2622 * defined on other compilers and should not be used in programs that
2623 * are intended to be portable to those compilers.
2625 * This is meant to be used to declare lists of a type with a cleanup
2626 * function. The type of the variable is a GList *. You
2627 * must not add your own '*'.
2629 * This macro can be used to avoid having to do explicit cleanups of
2630 * local variables when exiting functions. It often vastly simplifies
2631 * handling of error conditions, removing the need for various tricks
2632 * such as 'goto out' or repeating of cleanup code. It is also helpful
2633 * for non-error cases.
2635 * See also g_autoslist(), g_autoptr() and g_steal_pointer().
2637 * Since: 2.56
2641 * g_autoslist:
2642 * @TypeName: a supported variable type
2644 * Helper to declare a singly linked list variable with automatic deep cleanup.
2646 * The list is deeply freed, in a way appropriate to the specified type, when the
2647 * variable goes out of scope. The type must support this.
2649 * This feature is only supported on GCC and clang. This macro is not
2650 * defined on other compilers and should not be used in programs that
2651 * are intended to be portable to those compilers.
2653 * This is meant to be used to declare lists of a type with a cleanup
2654 * function. The type of the variable is a GSList *. You
2655 * must not add your own '*'.
2657 * This macro can be used to avoid having to do explicit cleanups of
2658 * local variables when exiting functions. It often vastly simplifies
2659 * handling of error conditions, removing the need for various tricks
2660 * such as 'goto out' or repeating of cleanup code. It is also helpful
2661 * for non-error cases.
2663 * See also g_autolist(), g_autoptr() and g_steal_pointer().
2665 * Since: 2.56
2669 * G_DEFINE_AUTOPTR_CLEANUP_FUNC:
2670 * @TypeName: a type name to define a g_autoptr() cleanup function for
2671 * @func: the cleanup function
2673 * Defines the appropriate cleanup function for a pointer type.
2675 * The function will not be called if the variable to be cleaned up
2676 * contains %NULL.
2678 * This will typically be the _free() or _unref() function for the given
2679 * type.
2681 * With this definition, it will be possible to use g_autoptr() with
2682 * @TypeName.
2684 * |[
2685 * G_DEFINE_AUTOPTR_CLEANUP_FUNC(GObject, g_object_unref)
2686 * ]|
2688 * This macro should be used unconditionally; it is a no-op on compilers
2689 * where cleanup is not supported.
2691 * Since: 2.44
2695 * G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC:
2696 * @TypeName: a type name to define a g_auto() cleanup function for
2697 * @func: the clear function
2699 * Defines the appropriate cleanup function for a type.
2701 * This will typically be the _clear() function for the given type.
2703 * With this definition, it will be possible to use g_auto() with
2704 * @TypeName.
2706 * |[
2707 * G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GQueue, g_queue_clear)
2708 * ]|
2710 * This macro should be used unconditionally; it is a no-op on compilers
2711 * where cleanup is not supported.
2713 * Since: 2.44
2717 * G_DEFINE_AUTO_CLEANUP_FREE_FUNC:
2718 * @TypeName: a type name to define a g_auto() cleanup function for
2719 * @func: the free function
2720 * @none: the "none" value for the type
2722 * Defines the appropriate cleanup function for a type.
2724 * With this definition, it will be possible to use g_auto() with
2725 * @TypeName.
2727 * This function will be rarely used. It is used with pointer-based
2728 * typedefs and non-pointer types where the value of the variable
2729 * represents a resource that must be freed. Two examples are #GStrv
2730 * and file descriptors.
2732 * @none specifies the "none" value for the type in question. It is
2733 * probably something like %NULL or -1. If the variable is found to
2734 * contain this value then the free function will not be called.
2736 * |[
2737 * G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStrv, g_strfreev, NULL)
2738 * ]|
2740 * This macro should be used unconditionally; it is a no-op on compilers
2741 * where cleanup is not supported.
2743 * Since: 2.44
2746 /* Windows Compatibility Functions {{{1 */
2749 * SECTION:windows
2750 * @title: Windows Compatibility Functions
2751 * @short_description: UNIX emulation on Windows
2753 * These functions provide some level of UNIX emulation on the
2754 * Windows platform. If your application really needs the POSIX
2755 * APIs, we suggest you try the Cygwin project.
2759 * MAXPATHLEN:
2761 * Provided for UNIX emulation on Windows; equivalent to UNIX
2762 * macro %MAXPATHLEN, which is the maximum length of a filename
2763 * (including full path).
2767 * G_WIN32_DLLMAIN_FOR_DLL_NAME:
2768 * @static: empty or "static"
2769 * @dll_name: the name of the (pointer to the) char array where
2770 * the DLL name will be stored. If this is used, you must also
2771 * include `windows.h`. If you need a more complex DLL entry
2772 * point function, you cannot use this
2774 * On Windows, this macro defines a DllMain() function that stores
2775 * the actual DLL name that the code being compiled will be included in.
2777 * On non-Windows platforms, expands to nothing.
2781 * G_WIN32_HAVE_WIDECHAR_API:
2783 * On Windows, this macro defines an expression which evaluates to
2784 * %TRUE if the code is running on a version of Windows where the wide
2785 * character versions of the Win32 API functions, and the wide character
2786 * versions of the C library functions work. (They are always present in
2787 * the DLLs, but don't work on Windows 9x and Me.)
2789 * On non-Windows platforms, it is not defined.
2791 * Since: 2.6
2796 * G_WIN32_IS_NT_BASED:
2798 * On Windows, this macro defines an expression which evaluates to
2799 * %TRUE if the code is running on an NT-based Windows operating system.
2801 * On non-Windows platforms, it is not defined.
2803 * Since: 2.6
2806 /* Epilogue {{{1 */
2807 /* vim: set foldmethod=marker: */