gmacros.h

Go to the documentation of this file.
00001 /* GLIB - Library of useful routines for C programming
00002  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 /*
00021  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
00022  * file for a list of people on the GLib Team.  See the ChangeLog
00023  * files for a list of changes.  These files are distributed with
00024  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
00025  */
00026 
00027 /* This file must not include any other glib header file and must thus
00028  * not refer to variables from glibconfig.h 
00029  */
00030 
00031 #ifndef __G_MACROS_H__
00032 #define __G_MACROS_H__
00033 
00034 /* Here we provide G_GNUC_EXTENSION as an alias for __extension__,
00035  * where this is valid. This allows for warningless compilation of
00036  * "long long" types even in the presence of '-ansi -pedantic'. 
00037  */
00038 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
00039 #  define G_GNUC_EXTENSION __extension__
00040 #else
00041 #  define G_GNUC_EXTENSION
00042 #endif
00043 
00044 /* Provide macros to feature the GCC function attribute.
00045  */
00046 #if    __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
00047 #define G_GNUC_PURE                            \
00048   __attribute__((pure))
00049 #else
00050 #define G_GNUC_PURE
00051 #endif
00052 
00053 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
00054 #define G_GNUC_PRINTF( format_idx, arg_idx )    \
00055   __attribute__((format (printf, format_idx, arg_idx)))
00056 #define G_GNUC_SCANF( format_idx, arg_idx )     \
00057   __attribute__((format (scanf, format_idx, arg_idx)))
00058 #define G_GNUC_FORMAT( arg_idx )                \
00059   __attribute__((format_arg (arg_idx)))
00060 #define G_GNUC_NORETURN                         \
00061   __attribute__((noreturn))
00062 #define G_GNUC_CONST                            \
00063   __attribute__((const))
00064 #define G_GNUC_UNUSED                           \
00065   __attribute__((unused))
00066 #else   /* !__GNUC__ */
00067 #define G_GNUC_PRINTF( format_idx, arg_idx )
00068 #define G_GNUC_SCANF( format_idx, arg_idx )
00069 #define G_GNUC_FORMAT( arg_idx )
00070 #define G_GNUC_NORETURN
00071 #define G_GNUC_CONST
00072 #define G_GNUC_UNUSED
00073 #endif  /* !__GNUC__ */
00074 
00075 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
00076  * macros, so we can refer to them as strings unconditionally.
00077  */
00078 #ifdef  __GNUC__
00079 #define G_GNUC_FUNCTION         __FUNCTION__
00080 #define G_GNUC_PRETTY_FUNCTION  __PRETTY_FUNCTION__
00081 #else   /* !__GNUC__ */
00082 #define G_GNUC_FUNCTION         ""
00083 #define G_GNUC_PRETTY_FUNCTION  ""
00084 #endif  /* !__GNUC__ */
00085 
00086 #define G_STRINGIFY(macro_or_string)    G_STRINGIFY_ARG (macro_or_string)
00087 #define G_STRINGIFY_ARG(contents)       #contents
00088 
00089 /* Provide a string identifying the current code position */
00090 #ifdef  __GNUC__
00091 #  define G_STRLOC      __FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
00092 #else
00093 #  define G_STRLOC      __FILE__ ":" G_STRINGIFY (__LINE__)
00094 #endif
00095 
00096 /* Guard C code in headers, while including them from C++ */
00097 #ifdef  __cplusplus
00098 # define G_BEGIN_DECLS  extern "C" {
00099 # define G_END_DECLS    }
00100 #else
00101 # define G_BEGIN_DECLS
00102 # define G_END_DECLS
00103 #endif
00104 
00105 /* Provide definitions for some commonly used macros.
00106  *  Some of them are only provided if they haven't already
00107  *  been defined. It is assumed that if they are already
00108  *  defined then the current definition is correct.
00109  */
00110 #ifndef NULL
00111 #  ifdef __cplusplus
00112 #    define NULL        (0L)
00113 #  else /* !__cplusplus */
00114 #    define NULL        ((void*) 0)
00115 #  endif /* !__cplusplus */
00116 #endif
00117 
00118 #ifndef FALSE
00119 #define FALSE   (0)
00120 #endif
00121 
00122 #ifndef TRUE
00123 #define TRUE    (!FALSE)
00124 #endif
00125 
00126 #undef  MAX
00127 #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
00128 
00129 #undef  MIN
00130 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
00131 
00132 #undef  ABS
00133 #define ABS(a)     (((a) < 0) ? -(a) : (a))
00134 
00135 #undef  CLAMP
00136 #define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
00137 
00138 /* Count the number of elements in an array. The array must be defined
00139  * as such; using this with a dynamically allocated array will give
00140  * incorrect results.
00141  */
00142 #define G_N_ELEMENTS(arr)               (sizeof (arr) / sizeof ((arr)[0]))
00143 
00144 /* Provide convenience macros for handling structure
00145  * fields through their offsets.
00146  */
00147 #define G_STRUCT_OFFSET(struct_type, member)    \
00148     ((glong) ((guint8*) &((struct_type*) 0)->member))
00149 #define G_STRUCT_MEMBER_P(struct_p, struct_offset)   \
00150     ((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
00151 #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset)   \
00152     (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
00153 
00154 /* Provide simple macro statement wrappers (adapted from Perl):
00155  *  G_STMT_START { statements; } G_STMT_END;
00156  *  can be used as a single statement, as in
00157  *  if (x) G_STMT_START { ... } G_STMT_END; else ...
00158  *
00159  *  For gcc we will wrap the statements within `({' and `})' braces.
00160  *  For SunOS they will be wrapped within `if (1)' and `else (void) 0',
00161  *  and otherwise within `do' and `while (0)'.
00162  */
00163 #if !(defined (G_STMT_START) && defined (G_STMT_END))
00164 #  if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
00165 #    define G_STMT_START        (void)(
00166 #    define G_STMT_END          )
00167 #  else
00168 #    if (defined (sun) || defined (__sun__))
00169 #      define G_STMT_START      if (1)
00170 #      define G_STMT_END        else (void)0
00171 #    else
00172 #      define G_STMT_START      do
00173 #      define G_STMT_END        while (0)
00174 #    endif
00175 #  endif
00176 #endif
00177 
00178 /* Allow the app programmer to select whether or not return values
00179  * (usually char*) are const or not.  Don't try using this feature for
00180  * functions with C++ linkage.
00181  */
00182 #ifdef G_DISABLE_CONST_RETURNS
00183 #define G_CONST_RETURN
00184 #else
00185 #define G_CONST_RETURN const
00186 #endif
00187 
00188 #endif /* __G_MACROS_H__ */

Generated on Tue Jul 5 14:14:41 2011 for ROOT_528-00b_version by  doxygen 1.5.1