include/begin_code.h
author Sam Lantinga <slouken@libsdl.org>
Sat, 31 Dec 2011 09:28:07 -0500
changeset 6138 4c64952a58fb
parent 5535 96594ac5fd1a
child 6204 dc2eb9370e82
permissions -rw-r--r--
Happy New Year!
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 /**
    23  *  \file begin_code.h
    24  *
    25  *  This file sets things up for C dynamic library function definitions,
    26  *  static inlined functions, and structures aligned at 4-byte alignment.
    27  *  If you don't like ugly C preprocessor code, don't look at this file. :)
    28  */
    29 
    30 /* This shouldn't be nested -- included it around code only. */
    31 #ifdef _begin_code_h
    32 #error Nested inclusion of begin_code.h
    33 #endif
    34 #define _begin_code_h
    35 
    36 /* Some compilers use a special export keyword */
    37 #ifndef DECLSPEC
    38 # if defined(__BEOS__) || defined(__HAIKU__)
    39 #  if defined(__GNUC__)
    40 #   define DECLSPEC	__declspec(dllexport)
    41 #  else
    42 #   define DECLSPEC	__declspec(export)
    43 #  endif
    44 # elif defined(__WIN32__)
    45 #  ifdef __BORLANDC__
    46 #   ifdef BUILD_SDL
    47 #    define DECLSPEC
    48 #   else
    49 #    define DECLSPEC	__declspec(dllimport)
    50 #   endif
    51 #  else
    52 #   define DECLSPEC	__declspec(dllexport)
    53 #  endif
    54 # else
    55 #  if defined(__GNUC__) && __GNUC__ >= 4
    56 #   define DECLSPEC	__attribute__ ((visibility("default")))
    57 #  else
    58 #   define DECLSPEC
    59 #  endif
    60 # endif
    61 #endif
    62 
    63 /* By default SDL uses the C calling convention */
    64 #ifndef SDLCALL
    65 #if defined(__WIN32__) && !defined(__GNUC__)
    66 #define SDLCALL __cdecl
    67 #else
    68 #define SDLCALL
    69 #endif
    70 #endif /* SDLCALL */
    71 
    72 /* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
    73 #ifdef __SYMBIAN32__
    74 #undef DECLSPEC
    75 #define DECLSPEC
    76 #endif /* __SYMBIAN32__ */
    77 
    78 /* Force structure packing at 4 byte alignment.
    79    This is necessary if the header is included in code which has structure
    80    packing set to an alternate value, say for loading structures from disk.
    81    The packing is reset to the previous value in close_code.h
    82  */
    83 #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
    84 #ifdef _MSC_VER
    85 #pragma warning(disable: 4103)
    86 #endif
    87 #ifdef __BORLANDC__
    88 #pragma nopackwarning
    89 #endif
    90 #pragma pack(push,4)
    91 #endif /* Compiler needs structure packing set */
    92 
    93 /* Set up compiler-specific options for inlining functions */
    94 #ifndef SDL_INLINE_OKAY
    95 #ifdef __GNUC__
    96 #define SDL_INLINE_OKAY
    97 #else
    98 /* Add any special compiler-specific cases here */
    99 #if defined(_MSC_VER) || defined(__BORLANDC__) || \
   100     defined(__DMC__) || defined(__SC__) || \
   101     defined(__WATCOMC__) || defined(__LCC__) || \
   102     defined(__DECC)
   103 #ifndef __inline__
   104 #define __inline__	__inline
   105 #endif
   106 #define SDL_INLINE_OKAY
   107 #else
   108 #if !defined(__MRC__) && !defined(_SGI_SOURCE)
   109 #ifndef __inline__
   110 #define __inline__ inline
   111 #endif
   112 #define SDL_INLINE_OKAY
   113 #endif /* Not a funky compiler */
   114 #endif /* Visual C++ */
   115 #endif /* GNU C */
   116 #endif /* SDL_INLINE_OKAY */
   117 
   118 /* If inlining isn't supported, remove "__inline__", turning static
   119    inlined functions into static functions (resulting in code bloat
   120    in all files which include the offending header files)
   121 */
   122 #ifndef SDL_INLINE_OKAY
   123 #define __inline__
   124 #endif
   125 
   126 /* Apparently this is needed by several Windows compilers */
   127 #if !defined(__MACH__)
   128 #ifndef NULL
   129 #ifdef __cplusplus
   130 #define NULL 0
   131 #else
   132 #define NULL ((void *)0)
   133 #endif
   134 #endif /* NULL */
   135 #endif /* ! Mac OS X - breaks precompiled headers */