begin_code.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 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. /* This shouldn't be nested -- included it around code only. */
  26. #ifdef _begin_code_h
  27. #error Nested inclusion of begin_code.h
  28. #endif
  29. #define _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. # else
  34. # define SDL_DEPRECATED
  35. # endif
  36. #endif
  37. #ifndef SDL_UNUSED
  38. # ifdef __GNUC__
  39. # define SDL_UNUSED __attribute__((unused))
  40. # else
  41. # define SDL_UNUSED
  42. # endif
  43. #endif
  44. /* Some compilers use a special export keyword */
  45. #ifndef DECLSPEC
  46. # if defined(__WIN32__) || defined(__WINRT__) || defined(__CYGWIN__) || defined(__GDK__)
  47. # ifdef DLL_EXPORT
  48. # define DECLSPEC __declspec(dllexport)
  49. # else
  50. # define DECLSPEC
  51. # endif
  52. # elif defined(__OS2__)
  53. # ifdef BUILD_SDL
  54. # define DECLSPEC __declspec(dllexport)
  55. # else
  56. # define DECLSPEC
  57. # endif
  58. # else
  59. # if defined(__GNUC__) && __GNUC__ >= 4
  60. # define DECLSPEC __attribute__ ((visibility("default")))
  61. # else
  62. # define DECLSPEC
  63. # endif
  64. # endif
  65. #endif
  66. /* By default SDL uses the C calling convention */
  67. #ifndef SDLCALL
  68. #if (defined(__WIN32__) || defined(__WINRT__) || defined(__GDK__)) && !defined(__GNUC__)
  69. #define SDLCALL __cdecl
  70. #elif defined(__OS2__) || defined(__EMX__)
  71. #define SDLCALL _System
  72. # if defined (__GNUC__) && !defined(_System)
  73. # define _System /* for old EMX/GCC compat. */
  74. # endif
  75. #else
  76. #define SDLCALL
  77. #endif
  78. #endif /* SDLCALL */
  79. /* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
  80. #ifdef __SYMBIAN32__
  81. #undef DECLSPEC
  82. #define DECLSPEC
  83. #endif /* __SYMBIAN32__ */
  84. /* Force structure packing at 4 byte alignment.
  85. This is necessary if the header is included in code which has structure
  86. packing set to an alternate value, say for loading structures from disk.
  87. The packing is reset to the previous value in close_code.h
  88. */
  89. #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
  90. #ifdef _MSC_VER
  91. #pragma warning(disable: 4103)
  92. #endif
  93. #ifdef __clang__
  94. #pragma clang diagnostic ignored "-Wpragma-pack"
  95. #endif
  96. #ifdef __BORLANDC__
  97. #pragma nopackwarning
  98. #endif
  99. #ifdef _WIN64
  100. /* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
  101. #pragma pack(push,8)
  102. #else
  103. #pragma pack(push,4)
  104. #endif
  105. #endif /* Compiler needs structure packing set */
  106. #ifndef SDL_INLINE
  107. #if defined(__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. #ifndef SDL_FORCE_INLINE
  125. #if defined(_MSC_VER)
  126. #define SDL_FORCE_INLINE __forceinline
  127. #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  128. #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  129. #else
  130. #define SDL_FORCE_INLINE static SDL_INLINE
  131. #endif
  132. #endif /* SDL_FORCE_INLINE not defined */
  133. #ifndef SDL_NORETURN
  134. #if defined(__GNUC__)
  135. #define SDL_NORETURN __attribute__((noreturn))
  136. #elif defined(_MSC_VER)
  137. #define SDL_NORETURN __declspec(noreturn)
  138. #else
  139. #define SDL_NORETURN
  140. #endif
  141. #endif /* SDL_NORETURN not defined */
  142. /* Apparently this is needed by several Windows compilers */
  143. #if !defined(__MACH__)
  144. #ifndef NULL
  145. #ifdef __cplusplus
  146. #define NULL 0
  147. #else
  148. #define NULL ((void *)0)
  149. #endif
  150. #endif /* NULL */
  151. #endif /* ! Mac OS X - breaks precompiled headers */
  152. #ifndef SDL_FALLTHROUGH
  153. #if (defined(__cplusplus) && __cplusplus >= 201703L) || \
  154. (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L)
  155. #define SDL_FALLTHROUGH [[fallthrough]]
  156. #else
  157. #if defined(__has_attribute)
  158. #define _HAS_FALLTHROUGH __has_attribute(__fallthrough__)
  159. #else
  160. #define _HAS_FALLTHROUGH 0
  161. #endif /* __has_attribute */
  162. #if _HAS_FALLTHROUGH && \
  163. ((defined(__GNUC__) && __GNUC__ >= 7) || \
  164. (defined(__clang_major__) && __clang_major__ >= 10))
  165. #define SDL_FALLTHROUGH __attribute__((__fallthrough__))
  166. #else
  167. #define SDL_FALLTHROUGH do {} while (0) /* fallthrough */
  168. #endif /* _HAS_FALLTHROUGH */
  169. #undef _HAS_FALLTHROUGH
  170. #endif /* C++17 or C2x */
  171. #endif /* SDL_FALLTHROUGH not defined */