KallistiOS
git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
cdefs.h
Go to the documentation of this file.
1
/* KallistiOS ##version##
2
3
kos/cdefs.h
4
Copyright (C) 2002, 2004 Megan Potter
5
Copyright (C) 2020, 2023 Lawrence Sebald
6
Copyright (C) 2023 Falco Girgis
7
8
Based loosely around some stuff in BSD's sys/cdefs.h
9
*/
10
11
/** \file kos/cdefs.h
12
\brief Definitions for builtin attributes and compiler directives
13
\ingroup system_macros
14
15
This file contains definitions of various __attribute__ directives in
16
shorter forms for use in programs. These typically aid in optimizations
17
or provide the compiler with extra information about a symbol.
18
19
\author Megan Potter
20
\author Lawrence Sebald
21
\author Falco Girgis
22
*/
23
24
#ifndef __KOS_CDEFS_H
25
#define __KOS_CDEFS_H
26
27
#include <sys/cdefs.h>
28
29
/** \defgroup system_macros Macros
30
\brief Various common macros used throughout the codebase
31
\ingroup system
32
33
@{
34
*/
35
36
/* Check GCC version */
37
#if __GNUC__ <= 3
38
# warning Your GCC is too old. This will probably not work right.
39
#endif
40
41
/* Special function/variable attributes */
42
43
#ifndef __noreturn
44
/** \brief Identify a function that will never return. */
45
#define __noreturn __attribute__((__noreturn__))
46
#endif
47
48
#ifndef __pure
49
/** \brief Identify a function that has no side effects other than its return,
50
and only uses its arguments for any work. */
51
#define __pure __attribute__((__const__))
52
#endif
53
54
#ifndef __unused
55
/** \brief Identify a function or variable that may be unused. */
56
#define __unused __attribute__((__unused__))
57
#endif
58
59
#ifndef __used
60
/** \brief Prevent a symbol from being removed from the binary. */
61
#define __used __attribute__((used))
62
#endif
63
64
#ifndef __weak
65
/** \brief Identify a function or variable that may be overridden by another symbol. */
66
#define __weak __attribute__((weak))
67
#endif
68
69
#ifndef __dead2
70
/** \brief Alias for \ref __noreturn. For BSD compatibility. */
71
#define __dead2 __noreturn
/* BSD compat */
72
#endif
73
74
#ifndef __pure2
75
/** \brief Alias for \ref __pure. For BSD compatibility. */
76
#define __pure2 __pure
/* ditto */
77
#endif
78
79
#ifndef __likely
80
/** \brief Directive to inform the compiler the condition is in the likely path.
81
82
This can be used around conditionals or loops to help inform the
83
compiler which path to optimize for as the common-case.
84
85
\param exp Boolean expression which expected to be true.
86
87
\sa __unlikely()
88
*/
89
#define __likely(exp) __builtin_expect(!!(exp), 1)
90
#endif
91
92
#ifndef __unlikely
93
/** \brief Directive to inform the compiler the condition is in the unlikely path.
94
95
This can be used around conditionals or loops to help inform the
96
compiler which path to optimize against as the infrequent-case.
97
98
\param exp Boolean expression which is expected to be false.
99
100
\sa __likely()
101
*/
102
#define __unlikely(exp) __builtin_expect(!!(exp), 0)
103
#endif
104
105
#ifndef __deprecated
106
/** \brief Mark something as deprecated.
107
This should be used to warn users that a function/type/etc will be removed
108
in a future version of KOS. */
109
#define __deprecated __attribute__((deprecated))
110
#endif
111
112
#ifndef __depr
113
/** \brief Mark something as deprecated, with an informative message.
114
This should be used to warn users that a function/type/etc will be removed
115
in a future version of KOS and to suggest an alternative that they can use
116
instead.
117
\param m A string literal that is included with the warning message
118
at compile time. */
119
#define __depr(m) __attribute__((deprecated(m)))
120
#endif
121
122
/* Printf/Scanf-like declaration */
123
#ifndef __printflike
124
/** \brief Identify a function as accepting formatting like printf().
125
126
Using this macro allows GCC to typecheck calls to printf-like functions,
127
which can aid in finding mistakes.
128
129
\param fmtarg The argument number (1-based) of the format string.
130
\param firstvararg The argument number of the first vararg (the ...).
131
*/
132
#define __printflike(fmtarg, firstvararg) \
133
__attribute__((__format__ (__printf__, fmtarg, firstvararg)))
134
#endif
135
136
#ifndef __scanflike
137
/** \brief Identify a function as accepting formatting like scanf().
138
139
Using this macro allows GCC to typecheck calls to scanf-like functions,
140
which can aid in finding mistakes.
141
142
\param fmtarg The argument number (1-based) of the format string.
143
\param firstvararg The argument number of the first vararg (the ...).
144
*/
145
#define __scanflike(fmtarg, firstvararg) \
146
__attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
147
#endif
148
149
#if __GNUC__ >= 7
150
/** \brief Identify a case statement that is expected to fall through to the
151
statement underneath it. */
152
#define __fallthrough __attribute__((__fallthrough__))
153
#else
154
#define __fallthrough
/* Fall through */
155
#endif
156
157
#ifndef __always_inline
158
/** \brief Ask the compiler to \a always inline a given function. */
159
#define __always_inline inline __attribute__((__always_inline__))
160
#endif
161
162
#ifndef __no_inline
163
/** \brief Ask the compiler to \a never inline a given function. */
164
#define __no_inline __attribute__((__noinline__))
165
#endif
166
167
/* GCC macros for special cases */
168
/* #if __GNUC__ == */
169
170
#ifndef __RESTRICT
171
#if (__STDC_VERSION__ >= 199901L)
172
#define __RESTRICT restrict
173
#elif defined(__GNUC__) || defined(__GNUG__)
174
#define __RESTRICT __restrict__
175
#else
/* < C99 and not GCC */
176
#define __RESTRICT
177
#endif
178
#endif
/* !__RESTRICT */
179
180
#ifndef __GNUC__
181
#define __extension__
182
#endif
183
184
#ifndef __GNUC_STDC_INLINE__
185
#define inline __inline__
186
#endif
187
188
/** @} */
189
190
#endif
/* __KOS_CDEFS_H */
include
kos
cdefs.h
Generated by
1.11.0