| 148 /** |
153 /** |
| 149 * The attributed function always returns freshly allocated memory. |
154 * The attributed function always returns freshly allocated memory. |
| 150 */ |
155 */ |
| 151 #define cx_attr_malloc __attribute__((__malloc__)) |
156 #define cx_attr_malloc __attribute__((__malloc__)) |
| 152 |
157 |
| 153 #ifndef __clang__ |
158 #if !defined(__clang__) && __GNUC__ >= 11 |
| 154 /** |
159 /** |
| 155 * The pointer returned by the attributed function is supposed to be freed |
160 * The pointer returned by the attributed function is supposed to be freed |
| 156 * by @p freefunc. |
161 * by @p freefunc. |
| 157 * |
162 * |
| 158 * @param freefunc the function that shall be used to free the memory |
163 * @param freefunc the function that shall be used to free the memory |
| 238 * Takes one or two arguments: the index of the pointer and (optionally) the |
243 * Takes one or two arguments: the index of the pointer and (optionally) the |
| 239 * index of another argument specifying the maximum number of accessed bytes. |
244 * index of another argument specifying the maximum number of accessed bytes. |
| 240 */ |
245 */ |
| 241 #define cx_attr_access_w(...) cx_attr_access(__write_only__, __VA_ARGS__) |
246 #define cx_attr_access_w(...) cx_attr_access(__write_only__, __VA_ARGS__) |
| 242 |
247 |
| 243 #if __STDC_VERSION__ >= 202300L |
|
| 244 |
|
| 245 /** |
248 /** |
| 246 * Do not warn about unused variable. |
249 * Do not warn about unused variable. |
| 247 */ |
250 */ |
| 248 #define cx_attr_unused [[maybe_unused]] |
251 #define cx_attr_unused __attribute__((__unused__)) |
| 249 |
252 |
| 250 /** |
253 /** |
| 251 * Warn about discarded return value. |
254 * Warn about discarded return value. |
| 252 */ |
255 */ |
| 253 #define cx_attr_nodiscard [[nodiscard]] |
|
| 254 |
|
| 255 #else // no C23 |
|
| 256 |
|
| 257 /** |
|
| 258 * Do not warn about unused variable. |
|
| 259 */ |
|
| 260 #define cx_attr_unused __attribute__((__unused__)) |
|
| 261 |
|
| 262 /** |
|
| 263 * Warn about discarded return value. |
|
| 264 */ |
|
| 265 #define cx_attr_nodiscard __attribute__((__warn_unused_result__)) |
256 #define cx_attr_nodiscard __attribute__((__warn_unused_result__)) |
| 266 |
|
| 267 #endif // __STDC_VERSION__ |
|
| 268 |
257 |
| 269 |
258 |
| 270 // --------------------------------------------------------------------------- |
259 // --------------------------------------------------------------------------- |
| 271 // MSVC specifics |
260 // MSVC specifics |
| 272 // --------------------------------------------------------------------------- |
261 // --------------------------------------------------------------------------- |