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/**
23 * \file begin_code.h
24 *
25 * This file 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
30/* This shouldn't be nested -- included it around code only. */
31#ifdef SDL_begin_code_h
32#error Nested inclusion of begin_code.h
33#endif
34#define SDL_begin_code_h
35
36#ifndef SDL_DEPRECATED
37# if defined(__GNUC__) && (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
38# define SDL_DEPRECATED __attribute__((deprecated))
39# elif defined(_MSC_VER)
40# define SDL_DEPRECATED __declspec(deprecated)
41# else
42# define SDL_DEPRECATED
43# endif
44#endif
45
46#ifndef SDL_UNUSED
47# ifdef __GNUC__
48# define SDL_UNUSED __attribute__((unused))
49# else
50# define SDL_UNUSED
51# endif
52#endif
53
54/* Some compilers use a special export keyword */
55#ifndef DECLSPEC
56# if defined(__WIN32__) || defined(__WINRT__) || defined(__CYGWIN__) || defined(__GDK__)
57# ifdef DLL_EXPORT
58# define DECLSPEC __declspec(dllexport)
59# else
60# define DECLSPEC
61# endif
62# elif defined(__OS2__)
63# ifdef BUILD_SDL
64# define DECLSPEC __declspec(dllexport)
65# else
66# define DECLSPEC
67# endif
68# else
69# if defined(__GNUC__) && __GNUC__ >= 4
70# define DECLSPEC __attribute__ ((visibility("default")))
71# else
72# define DECLSPEC
73# endif
74# endif
75#endif
76
77/* By default SDL uses the C calling convention */
78#ifndef SDLCALL
79#if (defined(__WIN32__) || defined(__WINRT__) || defined(__GDK__)) && !defined(__GNUC__)
80#define SDLCALL __cdecl
81#elif defined(__OS2__) || defined(__EMX__)
82#define SDLCALL _System
83# if defined (__GNUC__) && !defined(_System)
84# define _System /* for old EMX/GCC compat. */
85# endif
86#else
87#define SDLCALL
88#endif
89#endif /* SDLCALL */
90
91/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
92#ifdef __SYMBIAN32__
93#undef DECLSPEC
94#define DECLSPEC
95#endif /* __SYMBIAN32__ */
96
97/* Force structure packing at 4 byte alignment.
98 This is necessary if the header is included in code which has structure
99 packing set to an alternate value, say for loading structures from disk.
100 The packing is reset to the previous value in close_code.h
101 */
102#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
103#ifdef _MSC_VER
104#pragma warning(disable: 4103)
105#endif
106#ifdef __clang__
107#pragma clang diagnostic ignored "-Wpragma-pack"
108#endif
109#ifdef __BORLANDC__
110#pragma nopackwarning
111#endif
112#ifdef _WIN64
113/* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
114#pragma pack(push,8)
115#else
116#pragma pack(push,4)
117#endif
118#endif /* Compiler needs structure packing set */
119
120#ifndef SDL_INLINE
121#if defined(__GNUC__)
122#define SDL_INLINE __inline__
123#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
124 defined(__DMC__) || defined(__SC__) || \
125 defined(__WATCOMC__) || defined(__LCC__) || \
126 defined(__DECC) || defined(__CC_ARM)
127#define SDL_INLINE __inline
128#ifndef __inline__
129#define __inline__ __inline
130#endif
131#else
132#define SDL_INLINE inline
133#ifndef __inline__
134#define __inline__ inline
135#endif
136#endif
137#endif /* SDL_INLINE not defined */
138
139#ifndef SDL_FORCE_INLINE
140#if defined(_MSC_VER)
141#define SDL_FORCE_INLINE __forceinline
142#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
143#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
144#else
145#define SDL_FORCE_INLINE static SDL_INLINE
146#endif
147#endif /* SDL_FORCE_INLINE not defined */
148
149#ifndef SDL_NORETURN
150#if defined(__GNUC__)
151#define SDL_NORETURN __attribute__((noreturn))
152#elif defined(_MSC_VER)
153#define SDL_NORETURN __declspec(noreturn)
154#else
155#define SDL_NORETURN
156#endif
157#endif /* SDL_NORETURN not defined */
158
159/* Apparently this is needed by several Windows compilers */
160#if !defined(__MACH__)
161#ifndef NULL
162#ifdef __cplusplus
163#define NULL 0
164#else
165#define NULL ((void *)0)
166#endif
167#endif /* NULL */
168#endif /* ! Mac OS X - breaks precompiled headers */
169
170#ifndef SDL_FALLTHROUGH
171#if (defined(__cplusplus) && __cplusplus >= 201703L) || \
172 (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L)
173#define SDL_FALLTHROUGH [[fallthrough]]
174#else
175#if defined(__has_attribute)
176#define SDL_HAS_FALLTHROUGH __has_attribute(__fallthrough__)
177#else
178#define SDL_HAS_FALLTHROUGH 0
179#endif /* __has_attribute */
180#if SDL_HAS_FALLTHROUGH && \
181 ((defined(__GNUC__) && __GNUC__ >= 7) || \
182 (defined(__clang_major__) && __clang_major__ >= 10))
183#define SDL_FALLTHROUGH __attribute__((__fallthrough__))
184#else
185#define SDL_FALLTHROUGH do {} while (0) /* fallthrough */
186#endif /* SDL_HAS_FALLTHROUGH */
187#undef SDL_HAS_FALLTHROUGH
188#endif /* C++17 or C2x */
189#endif /* SDL_FALLTHROUGH not defined */
190