begin_code.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2019 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. // Modified by Yao Wei Tjong for Urho3D
  19. /**
  20. * \file 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 _begin_code_h
  28. #error Nested inclusion of begin_code.h
  29. #endif
  30. #define _begin_code_h
  31. #ifndef SDL_DEPRECATED
  32. # if (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
  33. # define SDL_DEPRECATED __attribute__((deprecated))
  34. # else
  35. # define SDL_DEPRECATED
  36. # endif
  37. #endif
  38. #ifndef SDL_UNUSED
  39. # ifdef __GNUC__
  40. # define SDL_UNUSED __attribute__((unused))
  41. # else
  42. # define SDL_UNUSED
  43. # endif
  44. #endif
  45. /* Some compilers use a special export keyword */
  46. // Urho3D: Only export when it is being requested
  47. #ifdef SDL_EXPORTS
  48. #ifndef DECLSPEC
  49. # if defined(__WIN32__) || defined(__WINRT__)
  50. # ifdef __BORLANDC__
  51. # ifdef BUILD_SDL
  52. # define DECLSPEC
  53. # else
  54. # define DECLSPEC __declspec(dllimport)
  55. # endif
  56. # else
  57. # define DECLSPEC __declspec(dllexport)
  58. # endif
  59. # elif defined(__OS2__)
  60. # ifdef BUILD_SDL
  61. # define DECLSPEC __declspec(dllexport)
  62. # else
  63. # define DECLSPEC
  64. # endif
  65. # else
  66. # if defined(__GNUC__) && __GNUC__ >= 4
  67. # define DECLSPEC __attribute__ ((visibility("default")))
  68. # else
  69. # define DECLSPEC
  70. # endif
  71. # endif
  72. #endif
  73. #else
  74. # define DECLSPEC
  75. #endif
  76. /* By default SDL uses the C calling convention */
  77. #ifndef SDLCALL
  78. #if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
  79. #define SDLCALL __cdecl
  80. #elif defined(__OS2__) || defined(__EMX__)
  81. #define SDLCALL _System
  82. # if defined (__GNUC__) && !defined(_System)
  83. # define _System /* for old EMX/GCC compat. */
  84. # endif
  85. #else
  86. #define SDLCALL
  87. #endif
  88. #endif /* SDLCALL */
  89. /* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
  90. #ifdef __SYMBIAN32__
  91. #undef DECLSPEC
  92. #define DECLSPEC
  93. #endif /* __SYMBIAN32__ */
  94. /* Force structure packing at 4 byte alignment.
  95. This is necessary if the header is included in code which has structure
  96. packing set to an alternate value, say for loading structures from disk.
  97. The packing is reset to the previous value in close_code.h
  98. */
  99. #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
  100. #ifdef _MSC_VER
  101. #pragma warning(disable: 4103)
  102. #endif
  103. #ifdef __clang__
  104. #pragma clang diagnostic ignored "-Wpragma-pack"
  105. #endif
  106. #ifdef __BORLANDC__
  107. #pragma nopackwarning
  108. #endif
  109. #ifdef _M_X64
  110. /* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
  111. #pragma pack(push,8)
  112. #else
  113. #pragma pack(push,4)
  114. #endif
  115. #endif /* Compiler needs structure packing set */
  116. #ifndef SDL_INLINE
  117. #if defined(__GNUC__)
  118. #define SDL_INLINE __inline__
  119. #elif defined(_MSC_VER) || defined(__BORLANDC__) || \
  120. defined(__DMC__) || defined(__SC__) || \
  121. defined(__WATCOMC__) || defined(__LCC__) || \
  122. defined(__DECC) || defined(__CC_ARM)
  123. #define SDL_INLINE __inline
  124. #ifndef __inline__
  125. #define __inline__ __inline
  126. #endif
  127. #else
  128. #define SDL_INLINE inline
  129. #ifndef __inline__
  130. #define __inline__ inline
  131. #endif
  132. #endif
  133. #endif /* SDL_INLINE not defined */
  134. #ifndef SDL_FORCE_INLINE
  135. #if defined(_MSC_VER)
  136. #define SDL_FORCE_INLINE __forceinline
  137. #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  138. #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  139. #else
  140. #define SDL_FORCE_INLINE static SDL_INLINE
  141. #endif
  142. #endif /* SDL_FORCE_INLINE not defined */
  143. #ifndef SDL_NORETURN
  144. #if defined(__GNUC__)
  145. #define SDL_NORETURN __attribute__((noreturn))
  146. #elif defined(_MSC_VER)
  147. #define SDL_NORETURN __declspec(noreturn)
  148. #else
  149. #define SDL_NORETURN
  150. #endif
  151. #endif /* SDL_NORETURN not defined */
  152. /* Apparently this is needed by several Windows compilers */
  153. #if !defined(__MACH__)
  154. #ifndef NULL
  155. #ifdef __cplusplus
  156. #define NULL 0
  157. #else
  158. #define NULL ((void *)0)
  159. #endif
  160. #endif /* NULL */
  161. #endif /* ! Mac OS X - breaks precompiled headers */