1 /* $NetBSD: attrs.h,v 1.1.1.1 2010/12/12 15:19:11 adam Exp $ */ 2 3 /* 4 attrs.h - wrapper macros for the gcc __attribute__(()) directive 5 6 Copyright (C) 2007, 2008 Arthur de Jong 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Lesser General Public 10 License as published by the Free Software Foundation; either 11 version 2.1 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 21 02110-1301 USA 22 */ 23 24 #ifndef _COMPAT_ATTRS_H 25 #define _COMPAT_ATTRS_H 1 26 27 /* macro for testing the version of GCC */ 28 #define GCC_VERSION(major,minor) \ 29 ((__GNUC__ > (major)) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) 30 31 /* These are macros to use some gcc-specific flags in case the're available 32 and otherwise define them to empty strings. This allows us to give 33 the compiler some extra information. 34 See http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html 35 for a list of attributes supported by gcc */ 36 37 /* this is used to flag function parameters that are not used in the function 38 body. */ 39 #if GCC_VERSION(3,0) 40 #define UNUSED(x) x __attribute__((__unused__)) 41 #else 42 #define UNUSED(x) x 43 #endif 44 45 /* this is used to add extra format checking to the function calls as if this 46 was a printf()-like function */ 47 #if GCC_VERSION(3,0) 48 #define LIKE_PRINTF(format_idx,arg_idx) \ 49 __attribute__((__format__(__printf__,format_idx,arg_idx))) 50 #else 51 #define LIKE_PRINTF(format_idx,arg_idx) /* no attribute */ 52 #endif 53 54 /* indicates that the function is "pure": it's result is purely based on 55 the parameters and has no side effects or used static data */ 56 #if GCC_VERSION(3,0) 57 #define PURE __attribute__((__pure__)) 58 #else 59 #define PURE /* no attribute */ 60 #endif 61 62 /* the function returns a new data structure that has been freshly 63 allocated */ 64 #if GCC_VERSION(3,0) 65 #define LIKE_MALLOC __attribute__((__malloc__)) 66 #else 67 #define LIKE_MALLOC /* no attribute */ 68 #endif 69 70 /* the function's return value should be used by the caller */ 71 #if GCC_VERSION(3,4) 72 #define MUST_USE __attribute__((__warn_unused_result__)) 73 #else 74 #define MUST_USE /* no attribute */ 75 #endif 76 77 /* the function's return value should be used by the caller */ 78 #if GCC_VERSION(2,5) 79 #define NORETURN __attribute__((__noreturn__)) 80 #else 81 #define NORETURN /* no attribute */ 82 #endif 83 84 /* define __STRING if it's not yet defined */ 85 #ifndef __STRING 86 #ifdef __STDC__ 87 #define __STRING(x) #x 88 #else /* __STDC__ */ 89 #define __STRING(x) "x" 90 #endif /* not __STDC__ */ 91 #endif /* not __STRING */ 92 93 #endif /* not _COMPAT_ATTRS_H */ 94