Back to index

openldap  2.4.31
attrs.h
Go to the documentation of this file.
00001 /*
00002    attrs.h - wrapper macros for the gcc __attribute__(()) directive
00003 
00004    Copyright (C) 2007, 2008 Arthur de Jong
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with this library; if not, write to the Free Software
00018    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019    02110-1301 USA
00020 */
00021 
00022 #ifndef _COMPAT_ATTRS_H
00023 #define _COMPAT_ATTRS_H 1
00024 
00025 /* macro for testing the version of GCC */
00026 #define GCC_VERSION(major,minor) \
00027   ((__GNUC__ > (major)) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
00028 
00029 /* These are macros to use some gcc-specific flags in case the're available
00030    and otherwise define them to empty strings. This allows us to give
00031    the compiler some extra information.
00032    See http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
00033    for a list of attributes supported by gcc */
00034 
00035 /* this is used to flag function parameters that are not used in the function
00036    body. */
00037 #if GCC_VERSION(3,0)
00038 #define UNUSED(x)   x __attribute__((__unused__))
00039 #else
00040 #define UNUSED(x)   x
00041 #endif
00042 
00043 /* this is used to add extra format checking to the function calls as if this
00044    was a printf()-like function */
00045 #if GCC_VERSION(3,0)
00046 #define LIKE_PRINTF(format_idx,arg_idx) \
00047                     __attribute__((__format__(__printf__,format_idx,arg_idx)))
00048 #else
00049 #define LIKE_PRINTF(format_idx,arg_idx) /* no attribute */
00050 #endif
00051 
00052 /* indicates that the function is "pure": it's result is purely based on
00053    the parameters and has no side effects or used static data */
00054 #if GCC_VERSION(3,0)
00055 #define PURE        __attribute__((__pure__))
00056 #else
00057 #define PURE        /* no attribute */
00058 #endif
00059 
00060 /* the function returns a new data structure that has been freshly
00061    allocated */
00062 #if GCC_VERSION(3,0)
00063 #define LIKE_MALLOC __attribute__((__malloc__))
00064 #else
00065 #define LIKE_MALLOC /* no attribute */
00066 #endif
00067 
00068 /* the function's return value should be used by the caller */
00069 #if GCC_VERSION(3,4)
00070 #define MUST_USE    __attribute__((__warn_unused_result__))
00071 #else
00072 #define MUST_USE    /* no attribute */
00073 #endif
00074 
00075 /* the function's return value should be used by the caller */
00076 #if GCC_VERSION(2,5)
00077 #define NORETURN    __attribute__((__noreturn__))
00078 #else
00079 #define NORETURN    /* no attribute */
00080 #endif
00081 
00082 /* define __STRING if it's not yet defined */
00083 #ifndef __STRING
00084 #ifdef __STDC__
00085 #define __STRING(x) #x
00086 #else /* __STDC__ */
00087 #define __STRING(x) "x"
00088 #endif /* not __STDC__ */
00089 #endif /* not __STRING */
00090 
00091 #endif /* not _COMPAT_ATTRS_H */