girara
macros.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: Zlib */
2
3#ifndef GIRARA_MACROS_H
4#define GIRARA_MACROS_H
5
6#ifndef __has_attribute
7#define __has_attribute(x) 0
8#endif
9
10#ifndef __has_builtin
11#define __has_builtin(x) 0
12#endif
13
14#if defined(__GNUC__) && defined(__GNUC_MINOR__)
15# define GIRARA_GNUC_CHECK(maj, min) \
16 (((__GNUC__ << 20) + (__GNUC_MINOR__ << 10)) >= (((maj) << 20) + ((min) << 10)))
17#else
18# define GIRARA_GNUC_CHECK(maj, min) 0
19#endif
20
21#ifndef GIRARA_PRINTF
22# if GIRARA_GNUC_CHECK(2, 5) || defined(__clang__)
23# define GIRARA_PRINTF(format_idx, arg_idx) \
24 __attribute__((__format__ (__printf__, format_idx, arg_idx)))
25# else
26# define GIRARA_PRINTF(format_idx, arg_idx)
27# endif
28#endif
29
30#ifndef GIRARA_UNUSED
31# if defined(__GNUC__) || defined(__clang__)
32# define GIRARA_UNUSED(x) UNUSED_ ## x __attribute__((unused))
33# elif defined(__LCLINT__)
34# define GIRARA_UNUSED(x) /*@unused@*/ x
35# else
36# define GIRARA_UNUSED(x) x
37# endif
38#endif
39
40#ifndef GIRARA_HIDDEN
41# if GIRARA_GNUC_CHECK(4, 0) || __has_attribute(visibility)
42# define GIRARA_HIDDEN __attribute__((visibility("hidden")))
43# elif defined(__SUNPRO_C)
44# define GIRARA_HIDDEN __hidden
45# else
46# define GIRARA_HIDDEN
47# endif
48#endif
49
50#ifndef GIRARA_VISIBLE
51# if GIRARA_GNUC_CHECK(4, 0) || __has_attribute(visibility)
52# define GIRARA_VISIBLE __attribute__((visibility("default")))
53# else
54# define GIRARA_VISIBLE
55# endif
56#endif
57
58#ifndef GIRARA_DEPRECATED
59# if defined(__GNUC__) || __has_attribute(deprecated)
60# define GIRARA_DEPRECATED(x) x __attribute__((deprecated))
61# define GIRARA_DEPRECATED_ __attribute__((deprecated))
62# else
63# define GIRARA_DEPRECATED(x) x
64# define GIRARA_DEPRECATED_
65# endif
66#endif
67
68#ifndef GIRARA_ALLOC_SIZE
69# if (!defined(__clang__) && GIRARA_GNUC_CHECK(4, 3)) || \
70 (defined(__clang__) && __has_attribute(__alloc_size__))
71# define GIRARA_ALLOC_SIZE(...) __attribute__((alloc_size(__VA_ARGS__)))
72# else
73# define GIRARA_ALLOC_SIZE(x)
74# endif
75#endif
76
77#ifndef GIRARA_DO_PRAGMA
78# if defined(__GNUC__) || defined(__clang__)
79# define GIRARA_DO_PRAGMA(x) _Pragma(#x)
80# else
81# define GIRARA_DO_PRAGMA(x)
82# endif
83#endif
84
85#ifndef GIRARA_IGNORE_DEPRECATED
86# define GIRARA_IGNORE_DEPRECATED \
87 GIRARA_DO_PRAGMA(GCC diagnostic push) \
88 GIRARA_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
89#endif
90
91#ifndef GIRARA_UNIGNORE
92# define GIRARA_UNIGNORE \
93 GIRARA_DO_PRAGMA(GCC diagnostic pop)
94#endif
95
96#endif