SDL_begin_code.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  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. /* WIKI CATEGORY: BeginCode */
  19. /**
  20. * \file SDL_begin_code.h
  21. *
  22. * This file sets things up for C dynamic library function definitions,
  23. * static inlined functions, and structures aligned at 4-byte alignment.
  24. * If you don't like ugly C preprocessor code, don't look at this file. :)
  25. */
  26. /* This shouldn't be nested -- included it around code only. */
  27. #ifdef SDL_begin_code_h
  28. #error Nested inclusion of SDL_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(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINRT) || defined(SDL_PLATFORM_CYGWIN) || defined(SDL_PLATFORM_GDK)
  50. # ifdef DLL_EXPORT
  51. # define DECLSPEC __declspec(dllexport)
  52. # else
  53. # define DECLSPEC
  54. # endif
  55. # else
  56. # if defined(__GNUC__) && __GNUC__ >= 4
  57. # define DECLSPEC __attribute__ ((visibility("default")))
  58. # else
  59. # define DECLSPEC
  60. # endif
  61. # endif
  62. #endif
  63. /* By default SDL uses the C calling convention */
  64. #ifndef SDLCALL
  65. #if (defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINRT) || defined(SDL_PLATFORM_GDK)) && !defined(__GNUC__)
  66. #define SDLCALL __cdecl
  67. #else
  68. #define SDLCALL
  69. #endif
  70. #endif /* SDLCALL */
  71. /* Force structure packing at 4 byte alignment.
  72. This is necessary if the header is included in code which has structure
  73. packing set to an alternate value, say for loading structures from disk.
  74. The packing is reset to the previous value in SDL_close_code.h
  75. */
  76. #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
  77. #ifdef _MSC_VER
  78. #pragma warning(disable: 4103)
  79. #endif
  80. #ifdef __clang__
  81. #pragma clang diagnostic ignored "-Wpragma-pack"
  82. #endif
  83. #ifdef __BORLANDC__
  84. #pragma nopackwarning
  85. #endif
  86. #ifdef _WIN64
  87. /* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
  88. #pragma pack(push,8)
  89. #else
  90. #pragma pack(push,4)
  91. #endif
  92. #endif /* Compiler needs structure packing set */
  93. #ifndef SDL_INLINE
  94. #ifdef __GNUC__
  95. #define SDL_INLINE __inline__
  96. #elif defined(_MSC_VER) || defined(__BORLANDC__) || \
  97. defined(__DMC__) || defined(__SC__) || \
  98. defined(__WATCOMC__) || defined(__LCC__) || \
  99. defined(__DECC) || defined(__CC_ARM)
  100. #define SDL_INLINE __inline
  101. #ifndef __inline__
  102. #define __inline__ __inline
  103. #endif
  104. #else
  105. #define SDL_INLINE inline
  106. #ifndef __inline__
  107. #define __inline__ inline
  108. #endif
  109. #endif
  110. #endif /* SDL_INLINE not defined */
  111. #ifndef SDL_FORCE_INLINE
  112. #ifdef _MSC_VER
  113. #define SDL_FORCE_INLINE __forceinline
  114. #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  115. #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  116. #else
  117. #define SDL_FORCE_INLINE static SDL_INLINE
  118. #endif
  119. #endif /* SDL_FORCE_INLINE not defined */
  120. #ifndef SDL_NORETURN
  121. #ifdef __GNUC__
  122. #define SDL_NORETURN __attribute__((noreturn))
  123. #elif defined(_MSC_VER)
  124. #define SDL_NORETURN __declspec(noreturn)
  125. #else
  126. #define SDL_NORETURN
  127. #endif
  128. #endif /* SDL_NORETURN not defined */
  129. /* Apparently this is needed by several Windows compilers */
  130. #ifndef __MACH__
  131. #ifndef NULL
  132. #ifdef __cplusplus
  133. #define NULL 0
  134. #else
  135. #define NULL ((void *)0)
  136. #endif
  137. #endif /* NULL */
  138. #endif /* ! macOS - breaks precompiled headers */
  139. #ifndef SDL_FALLTHROUGH
  140. #if (defined(__cplusplus) && __cplusplus >= 201703L) || \
  141. (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L)
  142. #define SDL_FALLTHROUGH [[fallthrough]]
  143. #else
  144. #ifdef __has_attribute
  145. #define SDL_HAS_FALLTHROUGH __has_attribute(__fallthrough__)
  146. #else
  147. #define SDL_HAS_FALLTHROUGH 0
  148. #endif /* __has_attribute */
  149. #if SDL_HAS_FALLTHROUGH && \
  150. ((defined(__GNUC__) && __GNUC__ >= 7) || \
  151. (defined(__clang_major__) && __clang_major__ >= 10))
  152. #define SDL_FALLTHROUGH __attribute__((__fallthrough__))
  153. #else
  154. #define SDL_FALLTHROUGH do {} while (0) /* fallthrough */
  155. #endif /* SDL_HAS_FALLTHROUGH */
  156. #undef SDL_HAS_FALLTHROUGH
  157. #endif /* C++17 or C2x */
  158. #endif /* SDL_FALLTHROUGH not defined */
  159. #ifndef SDL_MALLOC
  160. #if defined(__GNUC__) && (__GNUC__ >= 3)
  161. #define SDL_MALLOC __attribute__((malloc))
  162. /** FIXME
  163. #elif defined(_MSC_VER)
  164. #define SDL_MALLOC __declspec(allocator) __desclspec(restrict)
  165. **/
  166. #else
  167. #define SDL_MALLOC
  168. #endif
  169. #endif /* SDL_MALLOC not defined */
  170. #ifndef SDL_ALLOC_SIZE
  171. #if (defined(__clang__) && __clang_major__ >= 4) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
  172. #define SDL_ALLOC_SIZE(p) __attribute__((alloc_size(p)))
  173. #elif defined(_MSC_VER)
  174. #define SDL_ALLOC_SIZE(p)
  175. #else
  176. #define SDL_ALLOC_SIZE(p)
  177. #endif
  178. #endif /* SDL_ALLOC_SIZE not defined */
  179. #ifndef SDL_ALLOC_SIZE2
  180. #if (defined(__clang__) && __clang_major__ >= 4) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
  181. #define SDL_ALLOC_SIZE2(p1, p2) __attribute__((alloc_size(p1, p2)))
  182. #elif defined(_MSC_VER)
  183. #define SDL_ALLOC_SIZE2(p1, p2)
  184. #else
  185. #define SDL_ALLOC_SIZE2(p1, p2)
  186. #endif
  187. #endif /* SDL_ALLOC_SIZE2 not defined */