|
Packit |
6bd9ab |
/*
|
|
Packit |
6bd9ab |
attrs.h - wrapper macros for the gcc __attribute__(()) directive
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
Copyright (C) 2007, 2008, 2012 Arthur de Jong
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
This library is free software; you can redistribute it and/or
|
|
Packit |
6bd9ab |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
License as published by the Free Software Foundation; either
|
|
Packit |
6bd9ab |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
This library is distributed in the hope that it will be useful,
|
|
Packit |
6bd9ab |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6bd9ab |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6bd9ab |
Lesser General Public License for more details.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
License along with this library; if not, write to the Free Software
|
|
Packit |
6bd9ab |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit |
6bd9ab |
02110-1301 USA
|
|
Packit |
6bd9ab |
*/
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#ifndef COMPAT__ATTRS_H
|
|
Packit |
6bd9ab |
#define COMPAT__ATTRS_H 1
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* macro for testing the version of GCC */
|
|
Packit |
6bd9ab |
#define GCC_VERSION(major, minor) \
|
|
Packit |
6bd9ab |
((__GNUC__ > (major)) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* These are macros to use some gcc-specific flags in case the're available
|
|
Packit |
6bd9ab |
and otherwise define them to empty strings. This allows us to give
|
|
Packit |
6bd9ab |
the compiler some extra information.
|
|
Packit |
6bd9ab |
See http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
|
|
Packit |
6bd9ab |
for a list of attributes supported by gcc */
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* this is used to flag function parameters that are not used in the function
|
|
Packit |
6bd9ab |
body. */
|
|
Packit |
6bd9ab |
#if GCC_VERSION(3, 0)
|
|
Packit |
6bd9ab |
#define UNUSED(x) x __attribute__((__unused__))
|
|
Packit |
6bd9ab |
#else
|
|
Packit |
6bd9ab |
#define UNUSED(x) x
|
|
Packit |
6bd9ab |
#endif
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* this is used to add extra format checking to the function calls as if this
|
|
Packit |
6bd9ab |
was a printf()-like function */
|
|
Packit |
6bd9ab |
#if GCC_VERSION(3, 0)
|
|
Packit |
6bd9ab |
#define LIKE_PRINTF(format_idx, arg_idx) \
|
|
Packit |
6bd9ab |
__attribute__((__format__(__printf__, format_idx, arg_idx)))
|
|
Packit |
6bd9ab |
#else
|
|
Packit |
6bd9ab |
#define LIKE_PRINTF(format_idx, arg_idx) /* no attribute */
|
|
Packit |
6bd9ab |
#endif
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* indicates that the function is "pure": its result is purely based on
|
|
Packit |
6bd9ab |
the parameters and has no side effects or used static data */
|
|
Packit |
6bd9ab |
#if GCC_VERSION(3, 0)
|
|
Packit |
6bd9ab |
#define PURE __attribute__((__pure__))
|
|
Packit |
6bd9ab |
#else
|
|
Packit |
6bd9ab |
#define PURE /* no attribute */
|
|
Packit |
6bd9ab |
#endif
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* the function returns a new data structure that has been freshly
|
|
Packit |
6bd9ab |
allocated */
|
|
Packit |
6bd9ab |
#if GCC_VERSION(3, 0)
|
|
Packit |
6bd9ab |
#define LIKE_MALLOC __attribute__((__malloc__))
|
|
Packit |
6bd9ab |
#else
|
|
Packit |
6bd9ab |
#define LIKE_MALLOC /* no attribute */
|
|
Packit |
6bd9ab |
#endif
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* the function's return value should be used by the caller */
|
|
Packit |
6bd9ab |
#if GCC_VERSION(3, 4)
|
|
Packit |
6bd9ab |
#define MUST_USE __attribute__((__warn_unused_result__))
|
|
Packit |
6bd9ab |
#else
|
|
Packit |
6bd9ab |
#define MUST_USE /* no attribute */
|
|
Packit |
6bd9ab |
#endif
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* the function's return value should be used by the caller */
|
|
Packit |
6bd9ab |
#if GCC_VERSION(2, 5)
|
|
Packit |
6bd9ab |
#define NORETURN __attribute__((__noreturn__))
|
|
Packit |
6bd9ab |
#else
|
|
Packit |
6bd9ab |
#define NORETURN /* no attribute */
|
|
Packit |
6bd9ab |
#endif
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* we don't need an explicit break statement in this case block */
|
|
Packit |
6bd9ab |
#if GCC_VERSION(7, 0)
|
|
Packit |
6bd9ab |
#define FALLTHROUGH __attribute__((fallthrough))
|
|
Packit |
6bd9ab |
#else
|
|
Packit |
6bd9ab |
#define FALLTHROUGH /* no attribute */
|
|
Packit |
6bd9ab |
#endif
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* define __STRING if it's not yet defined */
|
|
Packit |
6bd9ab |
#ifndef __STRING
|
|
Packit |
6bd9ab |
#ifdef __STDC__
|
|
Packit |
6bd9ab |
#define __STRING(x) #x
|
|
Packit |
6bd9ab |
#else /* __STDC__ */
|
|
Packit |
6bd9ab |
#define __STRING(x) "x"
|
|
Packit |
6bd9ab |
#endif /* not __STDC__ */
|
|
Packit |
6bd9ab |
#endif /* not __STRING */
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#endif /* not COMPAT__ATTRS_H */
|