summaryrefslogtreecommitdiffstats
path: root/include/osmocom/core/defs.h
blob: aebe92586b15107d5915faaf8dc6f61c7fa7f617 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once

/*! \defgroup utils General-purpose utility functions
 *  @{
 */

/*! \file defs.h
 *  \brief General definitions that are meant to be included from header files.
 */

/*! \brief Check for gcc and version.
 *
 * \note Albeit glibc provides a features.h file that contains a similar
 *       definition (__GNUC_PREREQ), this definition has been copied from there
 *       to have it available with other libraries, too.
 *
 * \return != 0 iff gcc is used and it's version is at least maj.min.
 */
#if defined __GNUC__ && defined __GNUC_MINOR__
# define OSMO_GNUC_PREREQ(maj, min) \
	((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
# define OSMO_GNUC_PREREQ(maj, min) 0
#endif

/*! \brief Set the deprecated attribute with a message.
 */
#if defined(__clang__)
# define _OSMO_HAS_ATTRIBUTE_DEPRECATED __has_attribute(deprecated)
# define _OSMO_HAS_ATTRIBUTE_DEPRECATED_WITH_MESSAGE __has_extension(attribute_deprecated_with_message)
#elif defined(__GNUC__)
# define _OSMO_HAS_ATTRIBUTE_DEPRECATED 1
# define _OSMO_HAS_ATTRIBUTE_DEPRECATED_WITH_MESSAGE OSMO_GNUC_PREREQ(4,5)
#endif

#if _OSMO_HAS_ATTRIBUTE_DEPRECATED_WITH_MESSAGE
# define OSMO_DEPRECATED(text)  __attribute__((__deprecated__(text)))
#elif _OSMO_HAS_ATTRIBUTE_DEPRECATED
# define OSMO_DEPRECATED(text)  __attribute__((__deprecated__))
#else
# define OSMO_DEPRECATED(text)
#endif

#undef _OSMO_HAS_ATTRIBUTE_DEPRECATED_WITH_MESSAGE
#undef _OSMO_HAS_ATTRIBUTE_DEPRECATED

/*! @} */