SDL 3.0
SDL_begin_code.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/* WIKI CATEGORY: BeginCode */
23
24/**
25 * SDL_begin_code.h sets things up for C dynamic library function definitions,
26 * static inlined functions, and structures aligned at 4-byte alignment.
27 * If you don't like ugly C preprocessor code, don't look at this file. :)
28 *
29 * SDL's headers use this; applications generally should not include this
30 * header directly.
31 */
32
33/* This shouldn't be nested -- included it around code only. */
34#ifdef SDL_begin_code_h
35#error Nested inclusion of SDL_begin_code.h
36#endif
37#define SDL_begin_code_h
38
39#ifndef SDL_DEPRECATED
40# if defined(__GNUC__) && (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
41# define SDL_DEPRECATED __attribute__((deprecated))
42# elif defined(_MSC_VER)
43# define SDL_DEPRECATED __declspec(deprecated)
44# else
45# define SDL_DEPRECATED
46# endif
47#endif
48
49#ifndef SDL_UNUSED
50# ifdef __GNUC__
51# define SDL_UNUSED __attribute__((unused))
52# else
53# define SDL_UNUSED
54# endif
55#endif
56
57/* Some compilers use a special export keyword */
58#ifndef SDL_DECLSPEC
59# if defined(SDL_PLATFORM_WINDOWS)
60# ifdef DLL_EXPORT
61# define SDL_DECLSPEC __declspec(dllexport)
62# else
63# define SDL_DECLSPEC
64# endif
65# else
66# if defined(__GNUC__) && __GNUC__ >= 4
67# define SDL_DECLSPEC __attribute__ ((visibility("default")))
68# else
69# define SDL_DECLSPEC
70# endif
71# endif
72#endif
73
74/* By default SDL uses the C calling convention */
75#ifndef SDLCALL
76#if defined(SDL_PLATFORM_WINDOWS) && !defined(__GNUC__)
77#define SDLCALL __cdecl
78#else
79#define SDLCALL
80#endif
81#endif /* SDLCALL */
82
83/* Force structure packing at 4 byte alignment.
84 This is necessary if the header is included in code which has structure
85 packing set to an alternate value, say for loading structures from disk.
86 The packing is reset to the previous value in SDL_close_code.h
87 */
88#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
89#ifdef _MSC_VER
90#pragma warning(disable: 4103)
91#endif
92#ifdef __clang__
93#pragma clang diagnostic ignored "-Wpragma-pack"
94#endif
95#ifdef __BORLANDC__
96#pragma nopackwarning
97#endif
98#ifdef _WIN64
99/* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
100#pragma pack(push,8)
101#else
102#pragma pack(push,4)
103#endif
104#endif /* Compiler needs structure packing set */
105
106#ifndef SDL_INLINE
107#ifdef __GNUC__
108#define SDL_INLINE __inline__
109#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
110 defined(__DMC__) || defined(__SC__) || \
111 defined(__WATCOMC__) || defined(__LCC__) || \
112 defined(__DECC) || defined(__CC_ARM)
113#define SDL_INLINE __inline
114#ifndef __inline__
115#define __inline__ __inline
116#endif
117#else
118#define SDL_INLINE inline
119#ifndef __inline__
120#define __inline__ inline
121#endif
122#endif
123#endif /* SDL_INLINE not defined */
124
125#ifndef SDL_FORCE_INLINE
126#ifdef _MSC_VER
127#define SDL_FORCE_INLINE __forceinline
128#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
129#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
130#else
131#define SDL_FORCE_INLINE static SDL_INLINE
132#endif
133#endif /* SDL_FORCE_INLINE not defined */
134
135#ifndef SDL_NORETURN
136#ifdef __GNUC__
137#define SDL_NORETURN __attribute__((noreturn))
138#elif defined(_MSC_VER)
139#define SDL_NORETURN __declspec(noreturn)
140#else
141#define SDL_NORETURN
142#endif
143#endif /* SDL_NORETURN not defined */
144
145#ifdef __clang__
146#if __has_feature(attribute_analyzer_noreturn)
147#define SDL_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
148#endif
149#endif
150
151#ifndef SDL_ANALYZER_NORETURN
152#define SDL_ANALYZER_NORETURN
153#endif
154
155/* Apparently this is needed by several Windows compilers */
156#ifndef __MACH__
157#ifndef NULL
158#ifdef __cplusplus
159#define NULL 0
160#else
161#define NULL ((void *)0)
162#endif
163#endif /* NULL */
164#endif /* ! macOS - breaks precompiled headers */
165
166#ifndef SDL_FALLTHROUGH
167#if (defined(__cplusplus) && __cplusplus >= 201703L) || \
168 (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L)
169#define SDL_FALLTHROUGH [[fallthrough]]
170#else
171#if defined(__has_attribute) && !defined(__SUNPRO_C) && !defined(__SUNPRO_CC)
172#define SDL_HAS_FALLTHROUGH __has_attribute(__fallthrough__)
173#else
174#define SDL_HAS_FALLTHROUGH 0
175#endif /* __has_attribute */
176#if SDL_HAS_FALLTHROUGH && \
177 ((defined(__GNUC__) && __GNUC__ >= 7) || \
178 (defined(__clang_major__) && __clang_major__ >= 10))
179#define SDL_FALLTHROUGH __attribute__((__fallthrough__))
180#else
181#define SDL_FALLTHROUGH do {} while (0) /* fallthrough */
182#endif /* SDL_HAS_FALLTHROUGH */
183#undef SDL_HAS_FALLTHROUGH
184#endif /* C++17 or C2x */
185#endif /* SDL_FALLTHROUGH not defined */
186
187#ifndef SDL_NODISCARD
188#if (defined(__cplusplus) && __cplusplus >= 201703L) || \
189 (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L)
190#define SDL_NODISCARD [[nodiscard]]
191#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
192#define SDL_NODISCARD __attribute__((warn_unused_result))
193#elif defined(_MSC_VER) && (_MSC_VER >= 1700)
194#define SDL_NODISCARD _Check_return_
195#else
196#define SDL_NODISCARD
197#endif /* C++17 or C23 */
198#endif /* SDL_NODISCARD not defined */
199
200#ifndef SDL_MALLOC
201#if defined(__GNUC__) && (__GNUC__ >= 3)
202#define SDL_MALLOC __attribute__((malloc))
203/** FIXME
204#elif defined(_MSC_VER)
205#define SDL_MALLOC __declspec(allocator) __desclspec(restrict)
206**/
207#else
208#define SDL_MALLOC
209#endif
210#endif /* SDL_MALLOC not defined */
211
212#ifndef SDL_ALLOC_SIZE
213#if (defined(__clang__) && __clang_major__ >= 4) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
214#define SDL_ALLOC_SIZE(p) __attribute__((alloc_size(p)))
215#elif defined(_MSC_VER)
216#define SDL_ALLOC_SIZE(p)
217#else
218#define SDL_ALLOC_SIZE(p)
219#endif
220#endif /* SDL_ALLOC_SIZE not defined */
221
222#ifndef SDL_ALLOC_SIZE2
223#if (defined(__clang__) && __clang_major__ >= 4) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
224#define SDL_ALLOC_SIZE2(p1, p2) __attribute__((alloc_size(p1, p2)))
225#elif defined(_MSC_VER)
226#define SDL_ALLOC_SIZE2(p1, p2)
227#else
228#define SDL_ALLOC_SIZE2(p1, p2)
229#endif
230#endif /* SDL_ALLOC_SIZE2 not defined */