begin_code.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. SDL - Simple DirectMedia Layer
  3. Copyright (C) 1997-2009 Sam Lantinga
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this library; if not, write to the Free
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. Sam Lantinga
  16. slouken@libsdl.org
  17. */
  18. /**
  19. * @file begin_code.h
  20. * This file sets things up for C dynamic library function definitions,
  21. * static inlined functions, and structures aligned at 4-byte alignment.
  22. * If you don't like ugly C preprocessor code, don't look at this file. :)
  23. */
  24. /**
  25. * @file begin_code.h
  26. * This shouldn't be nested -- included it around code only.
  27. */
  28. #ifdef _begin_code_h
  29. #error Nested inclusion of begin_code.h
  30. #endif
  31. #define _begin_code_h
  32. /**
  33. * @def DECLSPEC
  34. * Some compilers use a special export keyword
  35. */
  36. #ifndef DECLSPEC
  37. # if defined(__BEOS__) || defined(__HAIKU__)
  38. # if defined(__GNUC__)
  39. # define DECLSPEC __declspec(dllexport)
  40. # else
  41. # define DECLSPEC __declspec(export)
  42. # endif
  43. # elif defined(__WIN32__)
  44. # ifdef __BORLANDC__
  45. # ifdef BUILD_SDL
  46. # define DECLSPEC
  47. # else
  48. # define DECLSPEC __declspec(dllimport)
  49. # endif
  50. # else
  51. # define DECLSPEC __declspec(dllexport)
  52. # endif
  53. # elif defined(__OS2__)
  54. # ifdef __WATCOMC__
  55. # ifdef BUILD_SDL
  56. # define DECLSPEC __declspec(dllexport)
  57. # else
  58. # define DECLSPEC
  59. # endif
  60. # elif defined (__GNUC__) && __GNUC__ < 4
  61. # /* Added support for GCC-EMX <v4.x */
  62. # /* this is needed for XFree86/OS2 developement */
  63. # /* F. Ambacher(anakor@snafu.de) 05.2008 */
  64. # ifdef BUILD_SDL
  65. # define DECLSPEC __declspec(dllexport)
  66. # else
  67. # define DECLSPEC
  68. # endif
  69. # else
  70. # define DECLSPEC
  71. # endif
  72. # else
  73. # if defined(__GNUC__) && __GNUC__ >= 4
  74. # define DECLSPEC __attribute__ ((visibility("default")))
  75. # else
  76. # define DECLSPEC
  77. # endif
  78. # endif
  79. #endif
  80. /**
  81. * @def SDLCALL
  82. * By default SDL uses the C calling convention
  83. */
  84. #ifndef SDLCALL
  85. # if defined(__WIN32__) && !defined(__GNUC__)
  86. # define SDLCALL __cdecl
  87. # elif defined(__OS2__)
  88. # if defined (__GNUC__) && __GNUC__ < 4
  89. # /* Added support for GCC-EMX <v4.x */
  90. # /* this is needed for XFree86/OS2 developement */
  91. # /* F. Ambacher(anakor@snafu.de) 05.2008 */
  92. # define SDLCALL _cdecl
  93. # else
  94. # /* On other compilers on OS/2, we use the _System calling convention */
  95. # /* to be compatible with every compiler */
  96. # define SDLCALL _System
  97. # endif
  98. # else
  99. # define SDLCALL
  100. # endif
  101. #endif /* SDLCALL */
  102. #ifdef __SYMBIAN32__
  103. #ifndef EKA2
  104. #undef DECLSPEC
  105. #define DECLSPEC
  106. #elif !defined(__WINS__)
  107. #undef DECLSPEC
  108. #define DECLSPEC __declspec(dllexport)
  109. #endif /* !EKA2 */
  110. #endif /* __SYMBIAN32__ */
  111. /**
  112. * @file begin_code.h
  113. * Force structure packing at 4 byte alignment.
  114. * This is necessary if the header is included in code which has structure
  115. * packing set to an alternate value, say for loading structures from disk.
  116. * The packing is reset to the previous value in close_code.h
  117. */
  118. #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
  119. #ifdef _MSC_VER
  120. #pragma warning(disable: 4103)
  121. #endif
  122. #ifdef __BORLANDC__
  123. #pragma nopackwarning
  124. #endif
  125. #pragma pack(push,4)
  126. #elif (defined(__MWERKS__) && defined(__MACOS__))
  127. #pragma options align=mac68k4byte
  128. #pragma enumsalwaysint on
  129. #endif /* Compiler needs structure packing set */
  130. /**
  131. * @def SDL_INLINE_OKAY
  132. * Set up compiler-specific options for inlining functions
  133. */
  134. #ifndef SDL_INLINE_OKAY
  135. #ifdef __GNUC__
  136. #define SDL_INLINE_OKAY
  137. #else
  138. /* Add any special compiler-specific cases here */
  139. #if defined(_MSC_VER) || defined(__BORLANDC__) || \
  140. defined(__DMC__) || defined(__SC__) || \
  141. defined(__WATCOMC__) || defined(__LCC__) || \
  142. defined(__DECC) || defined(__EABI__)
  143. #ifndef __inline__
  144. #define __inline__ __inline
  145. #endif
  146. #define SDL_INLINE_OKAY
  147. #else
  148. #if !defined(__MRC__) && !defined(_SGI_SOURCE)
  149. #ifndef __inline__
  150. #define __inline__ inline
  151. #endif
  152. #define SDL_INLINE_OKAY
  153. #endif /* Not a funky compiler */
  154. #endif /* Visual C++ */
  155. #endif /* GNU C */
  156. #endif /* SDL_INLINE_OKAY */
  157. /**
  158. * @def __inline__
  159. * If inlining isn't supported, remove "__inline__", turning static
  160. * inlined functions into static functions (resulting in code bloat
  161. * in all files which include the offending header files)
  162. */
  163. #ifndef SDL_INLINE_OKAY
  164. #define __inline__
  165. #endif
  166. /**
  167. * @def NULL
  168. * Apparently this is needed by several Windows compilers
  169. */
  170. #if !defined(__MACH__)
  171. #ifndef NULL
  172. #ifdef __cplusplus
  173. #define NULL 0
  174. #else
  175. #define NULL ((void *)0)
  176. #endif
  177. #endif /* NULL */
  178. #endif /* ! Mac OS X - breaks precompiled headers */