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