include/begin_code.h
author Ozkan Sezer <sezeroz@gmail.com>
Sat, 24 Mar 2018 22:28:31 +0300
branchSDL-1.2
changeset 11966 0c7962a4336f
parent 6203 bc960ba38aae
permissions -rw-r--r--
remove unnecessary restrictions from SDLCALL and DECLSPEC macros for OS/2.
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 BUILD_SDL
slouken@1574
    62
#    define DECLSPEC	__declspec(dllexport)
icculus@1190
    63
#   else
slouken@1574
    64
#    define DECLSPEC
slouken@1574
    65
#   endif
icculus@1190
    66
# else
slouken@1595
    67
#  if defined(__GNUC__) && __GNUC__ >= 4
slouken@1574
    68
#   define DECLSPEC	__attribute__ ((visibility("default")))
slouken@1574
    69
#  else
slouken@1574
    70
#   define DECLSPEC
slouken@1574
    71
#  endif
slouken@0
    72
# endif
slouken@0
    73
#endif
slouken@0
    74
slouken@4217
    75
/** 
slouken@4217
    76
 *  @def SDLCALL
slouken@4217
    77
 *  By default SDL uses the C calling convention
slouken@4217
    78
 */
slouken@337
    79
#ifndef SDLCALL
icculus@4193
    80
# if defined(__WIN32__) && !defined(__GNUC__)
icculus@4193
    81
#  define SDLCALL __cdecl
icculus@4193
    82
# elif defined(__OS2__)
sezeroz@11966
    83
   /* But on OS/2, we use the _System calling convention */
sezeroz@11966
    84
   /* to be compatible with every compiler */
sezeroz@11966
    85
#  if defined (__GNUC__) && !defined(_System)
sezeroz@11966
    86
#   define _System /* For compatibility with old GCC/EMX */
icculus@4193
    87
#  endif
sezeroz@11966
    88
#  define SDLCALL _System
icculus@4193
    89
# else
icculus@4193
    90
#  define SDLCALL
icculus@4193
    91
# endif
slouken@337
    92
#endif /* SDLCALL */
slouken@337
    93
slouken@173
    94
#ifdef __SYMBIAN32__ 
icculus@3975
    95
#ifndef EKA2 
slouken@173
    96
#undef DECLSPEC
slouken@173
    97
#define DECLSPEC
icculus@3975
    98
#elif !defined(__WINS__)
icculus@3975
    99
#undef DECLSPEC
icculus@3975
   100
#define DECLSPEC __declspec(dllexport)
icculus@4091
   101
#endif /* !EKA2 */
icculus@4091
   102
#endif /* __SYMBIAN32__ */
slouken@173
   103
slouken@4217
   104
/**
slouken@4217
   105
 *  @file begin_code.h
slouken@4217
   106
 *  Force structure packing at 4 byte alignment.
slouken@4217
   107
 *  This is necessary if the header is included in code which has structure
slouken@4217
   108
 *  packing set to an alternate value, say for loading structures from disk.
slouken@4217
   109
 *  The packing is reset to the previous value in close_code.h 
slouken@0
   110
 */
slouken@288
   111
#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
slouken@0
   112
#ifdef _MSC_VER
slouken@0
   113
#pragma warning(disable: 4103)
slouken@0
   114
#endif
slouken@0
   115
#ifdef __BORLANDC__
slouken@0
   116
#pragma nopackwarning
slouken@0
   117
#endif
slouken@6203
   118
#ifdef _M_X64
slouken@6203
   119
/* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
slouken@6203
   120
#pragma pack(push,8)
slouken@6203
   121
#else
slouken@195
   122
#pragma pack(push,4)
slouken@6203
   123
#endif
slouken@1402
   124
#elif (defined(__MWERKS__) && defined(__MACOS__))
slouken@189
   125
#pragma options align=mac68k4byte
slouken@189
   126
#pragma enumsalwaysint on
slouken@0
   127
#endif /* Compiler needs structure packing set */
slouken@0
   128
slouken@4217
   129
/**
slouken@4217
   130
 *  @def SDL_INLINE_OKAY
slouken@4217
   131
 *  Set up compiler-specific options for inlining functions
slouken@4217
   132
 */
slouken@0
   133
#ifndef SDL_INLINE_OKAY
slouken@0
   134
#ifdef __GNUC__
slouken@0
   135
#define SDL_INLINE_OKAY
slouken@0
   136
#else
slouken@0
   137
/* Add any special compiler-specific cases here */
slouken@288
   138
#if defined(_MSC_VER) || defined(__BORLANDC__) || \
slouken@288
   139
    defined(__DMC__) || defined(__SC__) || \
slouken@1019
   140
    defined(__WATCOMC__) || defined(__LCC__) || \
icculus@3975
   141
    defined(__DECC) || defined(__EABI__)
slouken@288
   142
#ifndef __inline__
slouken@85
   143
#define __inline__	__inline
slouken@288
   144
#endif
slouken@85
   145
#define SDL_INLINE_OKAY
slouken@85
   146
#else
slouken@85
   147
#if !defined(__MRC__) && !defined(_SGI_SOURCE)
icculus@3965
   148
#ifndef __inline__
slouken@0
   149
#define __inline__ inline
icculus@3965
   150
#endif
slouken@0
   151
#define SDL_INLINE_OKAY
slouken@0
   152
#endif /* Not a funky compiler */
slouken@85
   153
#endif /* Visual C++ */
slouken@0
   154
#endif /* GNU C */
slouken@0
   155
#endif /* SDL_INLINE_OKAY */
slouken@0
   156
slouken@4217
   157
/**
slouken@4217
   158
 *  @def __inline__
slouken@4217
   159
 *  If inlining isn't supported, remove "__inline__", turning static
slouken@4217
   160
 *  inlined functions into static functions (resulting in code bloat
slouken@4217
   161
 *  in all files which include the offending header files)
slouken@4217
   162
 */
slouken@0
   163
#ifndef SDL_INLINE_OKAY
slouken@0
   164
#define __inline__
slouken@0
   165
#endif
slouken@0
   166
slouken@4217
   167
/**
slouken@4217
   168
 *  @def NULL
slouken@4217
   169
 *  Apparently this is needed by several Windows compilers
slouken@4217
   170
 */
slouken@346
   171
#if !defined(__MACH__)
slouken@288
   172
#ifndef NULL
slouken@288
   173
#ifdef __cplusplus
slouken@288
   174
#define NULL 0
slouken@288
   175
#else
slouken@288
   176
#define NULL ((void *)0)
slouken@288
   177
#endif
slouken@288
   178
#endif /* NULL */
slouken@1621
   179
#endif /* ! Mac OS X - breaks precompiled headers */