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