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