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