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 #ifndef GIRARA_PRINTF
15 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) || defined(__clang__)
16 # define GIRARA_PRINTF(format_idx, arg_idx) \
17  __attribute__((__format__ (__printf__, format_idx, arg_idx)))
18 # else
19 # define GIRARA_PRINTF(format_idx, arg_idx)
20 # endif
21 #endif
22 
23 #ifndef GIRARA_UNUSED
24 # if defined(__GNUC__) || defined(__clang__)
25 # define GIRARA_UNUSED(x) UNUSED_ ## x __attribute__((unused))
26 # elif defined(__LCLINT__)
27 # define GIRARA_UNUSED(x) /*@unused@*/ x
28 # else
29 # define GIRARA_UNUSED(x) x
30 # endif
31 #endif
32 
33 #ifndef GIRARA_HIDDEN
34 # if (defined(__GNUC__) && (__GNUC__ >= 4)) || __has_attribute(visibility)
35 # define GIRARA_HIDDEN __attribute__((visibility("hidden")))
36 # elif defined(__SUNPRO_C)
37 # define GIRARA_HIDDEN __hidden
38 # else
39 # define GIRARA_HIDDEN
40 # endif
41 #endif
42 
43 #ifndef GIRARA_VISIBLE
44 # if (defined(__GNUC__) && (__GNUC__ >= 4)) || __has_attribute(visibility)
45 # define GIRARA_VISIBLE __attribute__((visibility("default")))
46 # else
47 # define GIRARA_VISIBLE
48 # endif
49 #endif
50 
51 #ifndef GIRARA_DEPRECATED
52 # if defined(__GNUC__)
53 # define GIRARA_DEPRECATED(x) x __attribute__((deprecated))
54 # define GIRARA_DEPRECATED_ __attribute__((deprecated))
55 # else
56 # define GIRARA_DEPRECATED(x) x
57 # define GIRARA_DEPRECATED_
58 # endif
59 #endif
60 
61 #ifndef GIRARA_ALLOC_SIZE
62 # if (!defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || \
63  (defined(__clang__) && __has_attribute(__alloc_size__))
64 # define GIRARA_ALLOC_SIZE(...) __attribute__((alloc_size(__VA_ARGS__)))
65 # else
66 # define GIRARA_ALLOC_SIZE(x)
67 # endif
68 #endif
69 
70 #ifndef GIRARA_DO_PRAGMA
71 # if defined(__GNUC__) || defined(__clang__)
72 # define GIRARA_DO_PRAGMA(x) _Pragma(#x)
73 # else
74 # define GIRARA_DO_PRAGMA(x)
75 # endif
76 #endif
77 
78 #ifndef GIRARA_IGNORE_DEPRECATED
79 # define GIRARA_IGNORE_DEPRECATED \
80  GIRARA_DO_PRAGMA(GCC diagnostic push) \
81  GIRARA_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
82 #endif
83 
84 #ifndef GIRARA_UNIGNORE
85 # define GIRARA_UNIGNORE \
86  GIRARA_DO_PRAGMA(GCC diagnostic pop)
87 #endif
88 
89 #endif