19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Library General Public 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2 of the License, or (at your option) any later version. 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Library General Public License for more details. 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Library General Public 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @file begin_code.h 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * This file sets things up for C dynamic library function definitions, 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * static inlined functions, and structures aligned at 4-byte alignment. 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * If you don't like ugly C preprocessor code, don't look at this file. :) 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @file begin_code.h 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * This shouldn't be nested -- included it around code only. 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef _begin_code_h 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#error Nested inclusion of begin_code.h 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define _begin_code_h 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @def DECLSPEC 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Some compilers use a special export keyword 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef DECLSPEC 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# if defined(__BEOS__) || defined(__HAIKU__) 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# if defined(__GNUC__) 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define DECLSPEC 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# else 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define DECLSPEC __declspec(export) 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# endif 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# elif defined(__WIN32__) 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# ifdef __BORLANDC__ 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# ifdef BUILD_SDL 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define DECLSPEC 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# else 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define DECLSPEC __declspec(dllimport) 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# endif 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# else 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define DECLSPEC __declspec(dllexport) 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# endif 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# elif defined(__OS2__) 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# ifdef __WATCOMC__ 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# ifdef BUILD_SDL 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define DECLSPEC __declspec(dllexport) 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# else 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define DECLSPEC 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# endif 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# elif defined (__GNUC__) && __GNUC__ < 4 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# /* Added support for GCC-EMX <v4.x */ 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# /* this is needed for XFree86/OS2 developement */ 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# /* F. Ambacher(anakor@snafu.de) 05.2008 */ 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# ifdef BUILD_SDL 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define DECLSPEC __declspec(dllexport) 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# else 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define DECLSPEC 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# endif 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# else 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define DECLSPEC 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# endif 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# else 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# if defined(__GNUC__) && __GNUC__ >= 4 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define DECLSPEC __attribute__ ((visibility("default"))) 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# else 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define DECLSPEC 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# endif 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# endif 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @def SDLCALL 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * By default SDL uses the C calling convention 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef SDLCALL 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# if defined(__WIN32__) && !defined(__GNUC__) 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define SDLCALL __cdecl 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# elif defined(__OS2__) 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# if defined (__GNUC__) && __GNUC__ < 4 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# /* Added support for GCC-EMX <v4.x */ 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# /* this is needed for XFree86/OS2 developement */ 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# /* F. Ambacher(anakor@snafu.de) 05.2008 */ 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define SDLCALL _cdecl 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# else 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# /* On other compilers on OS/2, we use the _System calling convention */ 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# /* to be compatible with every compiler */ 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define SDLCALL _System 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# endif 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# else 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define SDLCALL 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# endif 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* SDLCALL */ 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef __SYMBIAN32__ 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef EKA2 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#undef DECLSPEC 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define DECLSPEC 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#elif !defined(__WINS__) 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#undef DECLSPEC 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define DECLSPEC __declspec(dllexport) 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* !EKA2 */ 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* __SYMBIAN32__ */ 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @file begin_code.h 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Force structure packing at 4 byte alignment. 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * This is necessary if the header is included in code which has structure 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * packing set to an alternate value, say for loading structures from disk. 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * The packing is reset to the previous value in close_code.h 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef _MSC_VER 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#pragma warning(disable: 4103) 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef __BORLANDC__ 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#pragma nopackwarning 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef _M_X64 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */ 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#pragma pack(push,8) 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#pragma pack(push,4) 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#elif (defined(__MWERKS__) && defined(__MACOS__)) 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#pragma options align=mac68k4byte 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#pragma enumsalwaysint on 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* Compiler needs structure packing set */ 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @def SDL_INLINE_OKAY 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Set up compiler-specific options for inlining functions 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef SDL_INLINE_OKAY 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef __GNUC__ 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define SDL_INLINE_OKAY 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Add any special compiler-specific cases here */ 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(_MSC_VER) || defined(__BORLANDC__) || \ 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall defined(__DMC__) || defined(__SC__) || \ 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall defined(__WATCOMC__) || defined(__LCC__) || \ 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall defined(__DECC) || defined(__EABI__) 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef __inline__ 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define __inline__ __inline 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define SDL_INLINE_OKAY 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if !defined(__MRC__) && !defined(_SGI_SOURCE) 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef __inline__ 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define __inline__ inline 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define SDL_INLINE_OKAY 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* Not a funky compiler */ 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* Visual C++ */ 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* GNU C */ 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* SDL_INLINE_OKAY */ 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @def __inline__ 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * If inlining isn't supported, remove "__inline__", turning static 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * inlined functions into static functions (resulting in code bloat 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * in all files which include the offending header files) 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef SDL_INLINE_OKAY 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define __inline__ 1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @def NULL 1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Apparently this is needed by several Windows compilers 1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if !defined(__MACH__) 1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef NULL 1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef __cplusplus 1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define NULL 0 1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define NULL ((void *)0) 1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* NULL */ 1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* ! Mac OS X - breaks precompiled headers */ 197