1b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet/*
2b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    SDL - Simple DirectMedia Layer
34458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
4b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
5b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    This library is free software; you can redistribute it and/or
6b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    modify it under the terms of the GNU Library General Public
7b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    License as published by the Free Software Foundation; either
8b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    version 2 of the License, or (at your option) any later version.
9b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
10b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    This library is distributed in the hope that it will be useful,
11b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    but WITHOUT ANY WARRANTY; without even the implied warranty of
12b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    Library General Public License for more details.
14b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
15b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    You should have received a copy of the GNU Library General Public
16b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    License along with this library; if not, write to the Free
17b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
19b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    Sam Lantinga
20b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    slouken@libsdl.org
21b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet*/
22b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
234458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
244458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  @file begin_code.h
254458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  This file sets things up for C dynamic library function definitions,
264458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  static inlined functions, and structures aligned at 4-byte alignment.
274458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  If you don't like ugly C preprocessor code, don't look at this file. :)
284458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall */
29b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
304458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
314458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  @file begin_code.h
324458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  This shouldn't be nested -- included it around code only.
334458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall */
34b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifdef _begin_code_h
35b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#error Nested inclusion of begin_code.h
36b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif
37b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define _begin_code_h
38b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
394458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
404458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  @def DECLSPEC
414458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  Some compilers use a special export keyword
424458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall */
43b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifndef DECLSPEC
444458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall# if defined(__BEOS__) || defined(__HAIKU__)
45b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#  if defined(__GNUC__)
464458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   define DECLSPEC
47b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#  else
48b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#   define DECLSPEC	__declspec(export)
49b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#  endif
50b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet# elif defined(__WIN32__)
51b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#  ifdef __BORLANDC__
52b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#   ifdef BUILD_SDL
53b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#    define DECLSPEC
54b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#   else
55b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#    define DECLSPEC	__declspec(dllimport)
56b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#   endif
57b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#  else
58b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#   define DECLSPEC	__declspec(dllexport)
59b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#  endif
60b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet# elif defined(__OS2__)
61b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#  ifdef __WATCOMC__
62b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#   ifdef BUILD_SDL
63b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#    define DECLSPEC	__declspec(dllexport)
64b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#   else
65b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#    define DECLSPEC
66b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#   endif
674458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#  elif defined (__GNUC__) && __GNUC__ < 4
684458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   /* Added support for GCC-EMX <v4.x */
694458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   /* this is needed for XFree86/OS2 developement */
704458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   /* F. Ambacher(anakor@snafu.de) 05.2008 */
714458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   ifdef BUILD_SDL
724458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#    define DECLSPEC    __declspec(dllexport)
734458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   else
744458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#    define DECLSPEC
754458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   endif
76b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#  else
77b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#   define DECLSPEC
78b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#  endif
79b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet# else
80b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#  if defined(__GNUC__) && __GNUC__ >= 4
81b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#   define DECLSPEC	__attribute__ ((visibility("default")))
82b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#  else
83b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#   define DECLSPEC
84b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#  endif
85b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet# endif
86b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif
87b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
884458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
894458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  @def SDLCALL
904458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  By default SDL uses the C calling convention
914458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall */
92b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifndef SDLCALL
934458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall# if defined(__WIN32__) && !defined(__GNUC__)
944458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#  define SDLCALL __cdecl
954458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall# elif defined(__OS2__)
964458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#  if defined (__GNUC__) && __GNUC__ < 4
974458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   /* Added support for GCC-EMX <v4.x */
984458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   /* this is needed for XFree86/OS2 developement */
994458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   /* F. Ambacher(anakor@snafu.de) 05.2008 */
1004458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   define SDLCALL _cdecl
1014458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#  else
1024458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   /* On other compilers on OS/2, we use the _System calling convention */
1034458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   /* to be compatible with every compiler */
1044458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#   define SDLCALL _System
1054458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#  endif
1064458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall# else
1074458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#  define SDLCALL
1084458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall# endif
109b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif /* SDLCALL */
110b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
111b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifdef __SYMBIAN32__
112b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifndef EKA2
113b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#undef DECLSPEC
114b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define DECLSPEC
115b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#elif !defined(__WINS__)
116b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#undef DECLSPEC
117b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define DECLSPEC __declspec(dllexport)
1184458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#endif /* !EKA2 */
1194458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#endif /* __SYMBIAN32__ */
120b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
1214458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
1224458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  @file begin_code.h
1234458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  Force structure packing at 4 byte alignment.
1244458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  This is necessary if the header is included in code which has structure
1254458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  packing set to an alternate value, say for loading structures from disk.
1264458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  The packing is reset to the previous value in close_code.h
127b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */
128b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
129b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifdef _MSC_VER
130b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#pragma warning(disable: 4103)
131b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif
132b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifdef __BORLANDC__
133b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#pragma nopackwarning
134b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif
1354458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#ifdef _M_X64
1364458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
1374458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#pragma pack(push,8)
1384458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#else
139b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#pragma pack(push,4)
1404458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall#endif
141b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#elif (defined(__MWERKS__) && defined(__MACOS__))
142b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#pragma options align=mac68k4byte
143b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#pragma enumsalwaysint on
144b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif /* Compiler needs structure packing set */
145b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
1464458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
1474458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  @def SDL_INLINE_OKAY
1484458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  Set up compiler-specific options for inlining functions
1494458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall */
150b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifndef SDL_INLINE_OKAY
151b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifdef __GNUC__
152b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_INLINE_OKAY
153b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#else
154b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet/* Add any special compiler-specific cases here */
155b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#if defined(_MSC_VER) || defined(__BORLANDC__) || \
156b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    defined(__DMC__) || defined(__SC__) || \
157b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    defined(__WATCOMC__) || defined(__LCC__) || \
158b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet    defined(__DECC) || defined(__EABI__)
159b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifndef __inline__
160b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define __inline__	__inline
161b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif
162b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_INLINE_OKAY
163b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#else
164b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#if !defined(__MRC__) && !defined(_SGI_SOURCE)
165b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifndef __inline__
166b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define __inline__ inline
167b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif
168b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_INLINE_OKAY
169b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif /* Not a funky compiler */
170b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif /* Visual C++ */
171b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif /* GNU C */
172b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif /* SDL_INLINE_OKAY */
173b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
1744458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
1754458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  @def __inline__
1764458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  If inlining isn't supported, remove "__inline__", turning static
1774458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  inlined functions into static functions (resulting in code bloat
1784458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  in all files which include the offending header files)
1794458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall */
180b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifndef SDL_INLINE_OKAY
181b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define __inline__
182b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif
183b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet
1844458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/**
1854458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  @def NULL
1864458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall *  Apparently this is needed by several Windows compilers
1874458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall */
188b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#if !defined(__MACH__)
189b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifndef NULL
190b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifdef __cplusplus
191b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define NULL 0
192b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#else
193b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define NULL ((void *)0)
194b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif
195b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif /* NULL */
196b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif /* ! Mac OS X - breaks precompiled headers */
197