SDL_begin_code.h 6.0 KB

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