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