begin_code.h 4.2 KB

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