2 attrs.h - wrapper macros for the gcc __attribute__(()) directive
4 Copyright (C) 2007, 2008 Arthur de Jong
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.
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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #ifndef _COMPAT_ATTRS_H
23 #define _COMPAT_ATTRS_H 1
25 /* macro for testing the version of GCC */
26 #define GCC_VERSION(major,minor) \
27 ((__GNUC__ > (major)) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
29 /* These are macros to use some gcc-specific flags in case the're available
30 and otherwise define them to empty strings. This allows us to give
31 the compiler some extra information.
32 See http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
33 for a list of attributes supported by gcc */
35 /* this is used to flag function parameters that are not used in the function
38 #define UNUSED(x) x __attribute__((__unused__))
43 /* this is used to add extra format checking to the function calls as if this
44 was a printf()-like function */
46 #define LIKE_PRINTF(format_idx,arg_idx) \
47 __attribute__((__format__(__printf__,format_idx,arg_idx)))
49 #define LIKE_PRINTF(format_idx,arg_idx) /* no attribute */
52 /* indicates that the function is "pure": it's result is purely based on
53 the parameters and has no side effects or used static data */
55 #define PURE __attribute__((__pure__))
57 #define PURE /* no attribute */
60 /* the function returns a new data structure that has been freshly
63 #define LIKE_MALLOC __attribute__((__malloc__))
65 #define LIKE_MALLOC /* no attribute */
68 /* the function's return value should be used by the caller */
70 #define MUST_USE __attribute__((__warn_unused_result__))
72 #define MUST_USE /* no attribute */
75 /* the function's return value should be used by the caller */
77 #define NORETURN __attribute__((__noreturn__))
79 #define NORETURN /* no attribute */
82 /* define __STRING if it's not yet defined */
85 #define __STRING(x) #x
87 #define __STRING(x) "x"
88 #endif /* not __STDC__ */
89 #endif /* not __STRING */
91 #endif /* not _COMPAT_ATTRS_H */