begin_code.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2013 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 (__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. /* Some compilers use a special export keyword */
  38. #ifndef DECLSPEC
  39. # if defined(__WIN32__)
  40. # ifdef __BORLANDC__
  41. # ifdef BUILD_SDL
  42. # define DECLSPEC
  43. # else
  44. # define DECLSPEC __declspec(dllimport)
  45. # endif
  46. # else
  47. # define DECLSPEC __declspec(dllexport)
  48. # endif
  49. # else
  50. # if defined(__GNUC__) && __GNUC__ >= 4
  51. # define DECLSPEC __attribute__ ((visibility("default")))
  52. # elif defined(__GNUC__) && __GNUC__ >= 2
  53. # define DECLSPEC __declspec(dllexport)
  54. # else
  55. # define DECLSPEC
  56. # endif
  57. # endif
  58. #endif
  59. /* By default SDL uses the C calling convention */
  60. #ifndef SDLCALL
  61. #if defined(__WIN32__) && !defined(__GNUC__)
  62. #define SDLCALL __cdecl
  63. #else
  64. #define SDLCALL
  65. #endif
  66. #endif /* SDLCALL */
  67. /* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
  68. #ifdef __SYMBIAN32__
  69. #undef DECLSPEC
  70. #define DECLSPEC
  71. #endif /* __SYMBIAN32__ */
  72. /* Force structure packing at 4 byte alignment.
  73. This is necessary if the header is included in code which has structure
  74. packing set to an alternate value, say for loading structures from disk.
  75. The packing is reset to the previous value in close_code.h
  76. */
  77. #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
  78. #ifdef _MSC_VER
  79. #pragma warning(disable: 4103)
  80. #endif
  81. #ifdef __BORLANDC__
  82. #pragma nopackwarning
  83. #endif
  84. #ifdef _M_X64
  85. /* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
  86. #pragma pack(push,8)
  87. #else
  88. #pragma pack(push,4)
  89. #endif
  90. #endif /* Compiler needs structure packing set */
  91. #ifndef __inline__
  92. /* Set up compiler-specific options for inlining functions */
  93. #ifndef SDL_INLINE_OKAY
  94. /* Add any special compiler-specific cases here */
  95. #if defined(_MSC_VER) || defined(__BORLANDC__) || \
  96. defined(__DMC__) || defined(__SC__) || \
  97. defined(__WATCOMC__) || defined(__LCC__) || \
  98. defined(__DECC)
  99. #ifndef __inline__
  100. #define __inline__ __inline
  101. #endif
  102. #define SDL_INLINE_OKAY 1
  103. #else
  104. #if !defined(__MRC__) && !defined(_SGI_SOURCE)
  105. #ifndef __inline__
  106. #define __inline__ inline
  107. #endif
  108. #define SDL_INLINE_OKAY 1
  109. #endif /* Not a funky compiler */
  110. #endif /* Visual C++ */
  111. #endif /* SDL_INLINE_OKAY */
  112. /* If inlining isn't supported, remove "__inline__", turning static
  113. inlined functions into static functions (resulting in code bloat
  114. in all files which include the offending header files)
  115. */
  116. #if !SDL_INLINE_OKAY || __STRICT_ANSI__
  117. #ifdef __inline__
  118. #undef __inline__
  119. #endif
  120. #define __inline__
  121. #endif
  122. #endif /* __inline__ not defined */
  123. #ifndef SDL_FORCE_INLINE
  124. #if defined(_MSC_VER)
  125. #define SDL_FORCE_INLINE __forceinline
  126. #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  127. #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  128. #else
  129. #define SDL_FORCE_INLINE static __inline__
  130. #endif
  131. #endif
  132. /* Apparently this is needed by several Windows compilers */
  133. #if !defined(__MACH__)
  134. #ifndef NULL
  135. #ifdef __cplusplus
  136. #define NULL 0
  137. #else
  138. #define NULL ((void *)0)
  139. #endif
  140. #endif /* NULL */
  141. #endif /* ! Mac OS X - breaks precompiled headers */