Go to the documentation of this file.
26 #ifndef AVUTIL_ATTRIBUTES_H
27 #define AVUTIL_ATTRIBUTES_H
30 # define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > (x) || __GNUC__ == (x) && __GNUC_MINOR__ >= (y))
31 # define AV_GCC_VERSION_AT_MOST(x,y) (__GNUC__ < (x) || __GNUC__ == (x) && __GNUC_MINOR__ <= (y))
33 # define AV_GCC_VERSION_AT_LEAST(x,y) 0
34 # define AV_GCC_VERSION_AT_MOST(x,y) 0
38 # define AV_HAS_BUILTIN(x) __has_builtin(x)
40 # define AV_HAS_BUILTIN(x) 0
43 #ifdef __has_attribute
44 # define AV_HAS_ATTRIBUTE(x) __has_attribute(x)
46 # define AV_HAS_ATTRIBUTE(x) 0
49 #if defined(__cplusplus) && \
50 defined(__has_cpp_attribute) && \
51 __cplusplus >= 201103L
52 # define AV_HAS_STD_ATTRIBUTE(x) __has_cpp_attribute(x)
53 #elif !defined(__cplusplus) && \
54 defined(__has_c_attribute) && \
55 defined(__STDC_VERSION__) && \
56 __STDC_VERSION__ >= 202311L
57 # define AV_HAS_STD_ATTRIBUTE(x) __has_c_attribute(x)
59 # define AV_HAS_STD_ATTRIBUTE(x) 0
62 #ifndef av_always_inline
63 #if AV_GCC_VERSION_AT_LEAST(3,1) || defined(__clang__)
64 # define av_always_inline __attribute__((always_inline)) inline
65 #elif defined(_MSC_VER)
66 # define av_always_inline __forceinline
68 # define av_always_inline inline
72 #ifndef av_extern_inline
73 #if defined(__ICL) && __ICL >= 1210 || defined(__GNUC_STDC_INLINE__)
74 # define av_extern_inline extern inline
76 # define av_extern_inline inline
80 #if AV_HAS_STD_ATTRIBUTE(nodiscard)
81 # define av_warn_unused_result [[nodiscard]]
82 #elif AV_GCC_VERSION_AT_LEAST(3,4) || defined(__clang__)
83 # define av_warn_unused_result __attribute__((warn_unused_result))
85 # define av_warn_unused_result
88 #if AV_GCC_VERSION_AT_LEAST(3,1) || defined(__clang__)
89 # define av_noinline __attribute__((noinline))
90 #elif defined(_MSC_VER)
91 # define av_noinline __declspec(noinline)
96 #if AV_GCC_VERSION_AT_LEAST(3,1) || defined(__clang__)
97 # define av_pure __attribute__((pure))
102 #if AV_GCC_VERSION_AT_LEAST(2,6) || defined(__clang__)
103 # define av_const __attribute__((const))
108 #if AV_GCC_VERSION_AT_LEAST(4,3) || defined(__clang__)
109 # define av_cold __attribute__((cold))
114 #if AV_GCC_VERSION_AT_LEAST(4,1) && !defined(__llvm__)
115 # define av_flatten __attribute__((flatten))
120 #if AV_HAS_STD_ATTRIBUTE(deprecated)
121 # define attribute_deprecated [[deprecated]]
122 #elif AV_GCC_VERSION_AT_LEAST(3,1) || defined(__clang__)
123 # define attribute_deprecated __attribute__((deprecated))
124 #elif defined(_MSC_VER)
125 # define attribute_deprecated __declspec(deprecated)
127 # define attribute_deprecated
135 #ifndef AV_NOWARN_DEPRECATED
136 #if AV_GCC_VERSION_AT_LEAST(4,6) || defined(__clang__)
137 # define AV_NOWARN_DEPRECATED(code) \
138 _Pragma("GCC diagnostic push") \
139 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \
141 _Pragma("GCC diagnostic pop")
142 #elif defined(_MSC_VER)
143 # define AV_NOWARN_DEPRECATED(code) \
144 __pragma(warning(push)) \
145 __pragma(warning(disable : 4996)) \
147 __pragma(warning(pop))
149 # define AV_NOWARN_DEPRECATED(code) code
153 #if AV_HAS_STD_ATTRIBUTE(maybe_unused)
154 # define av_unused [[maybe_unused]]
155 #elif defined(__GNUC__) || defined(__clang__)
156 # define av_unused __attribute__((unused))
166 #if AV_GCC_VERSION_AT_LEAST(3,1) || defined(__clang__)
167 # define av_used __attribute__((used))
172 #if AV_GCC_VERSION_AT_LEAST(3,3) || defined(__clang__)
173 # define av_alias __attribute__((may_alias))
178 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__INTEL_COMPILER)
179 # define av_uninit(x) x=x
181 # define av_uninit(x) x
184 #if defined(__GNUC__) || defined(__clang__)
185 # define av_builtin_constant_p __builtin_constant_p
187 # define av_builtin_constant_p(x) 0
195 #ifdef __MINGW_PRINTF_FORMAT
196 # define AV_PRINTF_FMT __MINGW_PRINTF_FORMAT
197 #elif AV_HAS_ATTRIBUTE(format)
198 # define AV_PRINTF_FMT __printf__
201 #ifdef __MINGW_SCANF_FORMAT
202 # define AV_SCANF_FMT __MINGW_SCANF_FORMAT
203 #elif AV_HAS_ATTRIBUTE(format)
204 # define AV_SCANF_FMT __scanf__
208 # define av_printf_format(fmtpos, attrpos) __attribute__((format(AV_PRINTF_FMT, fmtpos, attrpos)))
210 # define av_printf_format(fmtpos, attrpos)
214 # define av_scanf_format(fmtpos, attrpos) __attribute__((format(AV_SCANF_FMT, fmtpos, attrpos)))
216 # define av_scanf_format(fmtpos, attrpos)
219 #if AV_HAS_STD_ATTRIBUTE(noreturn)
220 # define av_noreturn [[noreturn]]
221 #elif AV_GCC_VERSION_AT_LEAST(2,5) || defined(__clang__)
222 # define av_noreturn __attribute__((noreturn))