begin_code.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file begin_code.h
  20. *
  21. * This file sets things up for C dynamic library function definitions,
  22. * static inlined functions, and structures aligned at 4-byte alignment.
  23. * If you don't like ugly C preprocessor code, don't look at this file. :)
  24. */
  25. /* WIKI CATEGORY: BeginCode */
  26. /* This shouldn't be nested -- included it around code only. */
  27. #ifdef SDL_begin_code_h
  28. #error Nested inclusion of begin_code.h
  29. #endif
  30. #define SDL_begin_code_h
  31. #ifndef SDL_DEPRECATED
  32. # if defined(__GNUC__) && (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
  33. # define SDL_DEPRECATED __attribute__((deprecated))
  34. # elif defined(_MSC_VER)
  35. # define SDL_DEPRECATED __declspec(deprecated)
  36. # else
  37. # define SDL_DEPRECATED
  38. # endif
  39. #endif
  40. #ifndef SDL_UNUSED
  41. # ifdef __GNUC__
  42. # define SDL_UNUSED __attribute__((unused))
  43. # else
  44. # define SDL_UNUSED
  45. # endif
  46. #endif
  47. /* Some compilers use a special export keyword */
  48. #ifndef DECLSPEC
  49. # if defined(__WIN32__) || defined(__WINRT__) || defined(__CYGWIN__) || defined(__GDK__)
  50. # ifdef DLL_EXPORT
  51. # define DECLSPEC __declspec(dllexport)
  52. # else
  53. # define DECLSPEC
  54. # endif
  55. # elif defined(__OS2__)
  56. # ifdef BUILD_SDL
  57. # define DECLSPEC __declspec(dllexport)
  58. # else
  59. # define DECLSPEC
  60. # endif
  61. # else
  62. # if defined(__GNUC__) && __GNUC__ >= 4
  63. # define DECLSPEC __attribute__ ((visibility("default")))
  64. # else
  65. # define DECLSPEC
  66. # endif
  67. # endif
  68. #endif
  69. /* By default SDL uses the C calling convention */
  70. #ifndef SDLCALL
  71. #if (defined(__WIN32__) || defined(__WINRT__) || defined(__GDK__)) && !defined(__GNUC__)
  72. #define SDLCALL __cdecl
  73. #elif defined(__OS2__) || defined(__EMX__)
  74. #define SDLCALL _System
  75. # if defined (__GNUC__) && !defined(_System)
  76. # define _System /* for old EMX/GCC compat. */
  77. # endif
  78. #else
  79. #define SDLCALL
  80. #endif
  81. #endif /* SDLCALL */
  82. /* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
  83. #ifdef __SYMBIAN32__
  84. #undef DECLSPEC
  85. #define DECLSPEC
  86. #endif /* __SYMBIAN32__ */
  87. /* Force structure packing at 4 byte alignment.
  88. This is necessary if the header is included in code which has structure
  89. packing set to an alternate value, say for loading structures from disk.
  90. The packing is reset to the previous value in close_code.h
  91. */
  92. #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
  93. #ifdef _MSC_VER
  94. #pragma warning(disable: 4103)
  95. #endif
  96. #ifdef __clang__
  97. #pragma clang diagnostic ignored "-Wpragma-pack"
  98. #endif
  99. #ifdef __BORLANDC__
  100. #pragma nopackwarning
  101. #endif
  102. #ifdef _WIN64
  103. /* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
  104. #pragma pack(push,8)
  105. #else
  106. #pragma pack(push,4)
  107. #endif
  108. #endif /* Compiler needs structure packing set */
  109. #ifndef SDL_INLINE
  110. #if defined(__GNUC__)
  111. #define SDL_INLINE __inline__
  112. #elif defined(_MSC_VER) || defined(__BORLANDC__) || \
  113. defined(__DMC__) || defined(__SC__) || \
  114. defined(__WATCOMC__) || defined(__LCC__) || \
  115. defined(__DECC) || defined(__CC_ARM)
  116. #define SDL_INLINE __inline
  117. #ifndef __inline__
  118. #define __inline__ __inline
  119. #endif
  120. #else
  121. #define SDL_INLINE inline
  122. #ifndef __inline__
  123. #define __inline__ inline
  124. #endif
  125. #endif
  126. #endif /* SDL_INLINE not defined */
  127. #ifndef SDL_FORCE_INLINE
  128. #if defined(_MSC_VER)
  129. #define SDL_FORCE_INLINE __forceinline
  130. #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  131. #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  132. #else
  133. #define SDL_FORCE_INLINE static SDL_INLINE
  134. #endif
  135. #endif /* SDL_FORCE_INLINE not defined */
  136. #ifndef SDL_NORETURN
  137. #if defined(__GNUC__)
  138. #define SDL_NORETURN __attribute__((noreturn))
  139. #elif defined(_MSC_VER)
  140. #define SDL_NORETURN __declspec(noreturn)
  141. #else
  142. #define SDL_NORETURN
  143. #endif
  144. #endif /* SDL_NORETURN not defined */
  145. /* Apparently this is needed by several Windows compilers */
  146. #if !defined(__MACH__)
  147. #ifndef NULL
  148. #ifdef __cplusplus
  149. #define NULL 0
  150. #else
  151. #define NULL ((void *)0)
  152. #endif
  153. #endif /* NULL */
  154. #endif /* ! Mac OS X - breaks precompiled headers */
  155. #ifndef SDL_FALLTHROUGH
  156. #if (defined(__cplusplus) && __cplusplus >= 201703L) || \
  157. (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L)
  158. #define SDL_FALLTHROUGH [[fallthrough]]
  159. #else
  160. #if defined(__has_attribute)
  161. #define SDL_HAS_FALLTHROUGH __has_attribute(__fallthrough__)
  162. #else
  163. #define SDL_HAS_FALLTHROUGH 0
  164. #endif /* __has_attribute */
  165. #if SDL_HAS_FALLTHROUGH && \
  166. ((defined(__GNUC__) && __GNUC__ >= 7) || \
  167. (defined(__clang_major__) && __clang_major__ >= 10))
  168. #define SDL_FALLTHROUGH __attribute__((__fallthrough__))
  169. #else
  170. #define SDL_FALLTHROUGH do {} while (0) /* fallthrough */
  171. #endif /* SDL_HAS_FALLTHROUGH */
  172. #undef SDL_HAS_FALLTHROUGH
  173. #endif /* C++17 or C2x */
  174. #endif /* SDL_FALLTHROUGH not defined */