FFmpeg
Loading...
Searching...
No Matches
attributes.h
Go to the documentation of this file.
1/*
2 * Copyright © 2025, Niklas Haas
3 * Copyright © 2018, VideoLAN and dav1d authors
4 * Copyright © 2018, Two Orioles, LLC
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * @file attributes.h
31 * @brief Platform and compiler attribute macros
32 *
33 * This header defines platform-specific compiler attributes used throughout
34 * the checkasm API for features like printf format checking and symbol visibility.
35 */
36
37#ifndef CHECKASM_ATTRIBUTES_H
38#define CHECKASM_ATTRIBUTES_H
39
40#include <stddef.h>
41
42/**
43 * @def CHECKASM_PRINTF(fmt, attr)
44 * @brief Printf-style format string checking attribute
45 *
46 * Enables compile-time checking of printf-style format strings and arguments
47 * when supported by the compiler. This helps catch format string errors at
48 * compile time rather than runtime.
49 *
50 * @param fmt Position of the format string parameter (1-indexed)
51 * @param attr Position of the first variadic argument (1-indexed)
52 */
53#ifndef CHECKASM_PRINTF
54 #ifdef __GNUC__
55 #if defined(__MINGW32__) && !defined(__clang__)
56 #define CHECKASM_PRINTF(fmt, attr) \
57 __attribute__((__format__(__gnu_printf__, fmt, attr)))
58 #else
59 #define CHECKASM_PRINTF(fmt, attr) \
60 __attribute__((__format__(__printf__, fmt, attr)))
61 #endif
62 #else
63 #define CHECKASM_PRINTF(fmt, attr)
64 #endif
65#endif
66
67/**
68 * @def CHECKASM_API
69 * @brief Symbol visibility attribute for public API functions
70 *
71 * Marks functions and variables as part of the public checkasm API. This
72 * ensures proper symbol export/import behavior across different platforms
73 * and build configurations.
74 *
75 * @note All public checkasm API functions are marked with this attribute.
76 */
77#ifndef CHECKASM_API
78 #ifdef _WIN32
79 #ifdef CHECKASM_BUILDING_DLL
80 #define CHECKASM_API __declspec(dllexport)
81 #else
82 #define CHECKASM_API
83 #endif
84 #elif defined(__OS2__)
85 #define CHECKASM_API __declspec(dllexport)
86 #else
87 #if __GNUC__ >= 4
88 #define CHECKASM_API __attribute__((visibility("default")))
89 #else
90 #define CHECKASM_API
91 #endif
92 #endif
93#endif
94
95#endif /* CHECKASM_ATTRIBUTES_H */