include/begin_code.h
author Ryan C. Gordon <icculus@icculus.org>
Mon, 14 Jan 2019 19:43:25 -0500
changeset 12548 1ae839748d02
parent 12503 806492103856
permissions -rw-r--r--
evdev: don't debug log on a BTN_TOUCH from a non-touch device.
slouken@8582
     1
/*
slouken@8582
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 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@11475
    64
# elif defined(__OS2__)
slouken@11287
    65
#   ifdef BUILD_SDL
slouken@11287
    66
#    define DECLSPEC    __declspec(dllexport)
slouken@11287
    67
#   else
slouken@11287
    68
#    define DECLSPEC
slouken@11287
    69
#   endif
slouken@8582
    70
# else
slouken@8582
    71
#  if defined(__GNUC__) && __GNUC__ >= 4
slouken@8582
    72
#   define DECLSPEC __attribute__ ((visibility("default")))
slouken@8582
    73
#  else
slouken@8582
    74
#   define DECLSPEC
slouken@8582
    75
#  endif
slouken@8582
    76
# endif
slouken@8582
    77
#endif
slouken@8582
    78
slouken@8582
    79
/* By default SDL uses the C calling convention */
slouken@8582
    80
#ifndef SDLCALL
slouken@8582
    81
#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
slouken@8582
    82
#define SDLCALL __cdecl
slouken@11287
    83
#elif defined(__OS2__) || defined(__EMX__)
slouken@11287
    84
#define SDLCALL _System
slouken@11287
    85
# if defined (__GNUC__) && !defined(_System)
slouken@11287
    86
#  define _System /* for old EMX/GCC compat.  */
slouken@11287
    87
# endif
slouken@8582
    88
#else
slouken@8582
    89
#define SDLCALL
slouken@8582
    90
#endif
slouken@8582
    91
#endif /* SDLCALL */
slouken@8582
    92
slouken@8582
    93
/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
slouken@8582
    94
#ifdef __SYMBIAN32__
slouken@8582
    95
#undef DECLSPEC
slouken@8582
    96
#define DECLSPEC
slouken@8582
    97
#endif /* __SYMBIAN32__ */
slouken@8582
    98
slouken@8582
    99
/* Force structure packing at 4 byte alignment.
slouken@8582
   100
   This is necessary if the header is included in code which has structure
slouken@8582
   101
   packing set to an alternate value, say for loading structures from disk.
slouken@8582
   102
   The packing is reset to the previous value in close_code.h
slouken@8582
   103
 */
slouken@8582
   104
#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
slouken@8582
   105
#ifdef _MSC_VER
slouken@8582
   106
#pragma warning(disable: 4103)
slouken@8582
   107
#endif
slouken@8582
   108
#ifdef __BORLANDC__
slouken@8582
   109
#pragma nopackwarning
slouken@8582
   110
#endif
slouken@8582
   111
#ifdef _M_X64
slouken@8582
   112
/* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
slouken@8582
   113
#pragma pack(push,8)
slouken@8582
   114
#else
slouken@8582
   115
#pragma pack(push,4)
slouken@8582
   116
#endif
slouken@8582
   117
#endif /* Compiler needs structure packing set */
slouken@8582
   118
slouken@8582
   119
#ifndef SDL_INLINE
slouken@8582
   120
#if defined(__GNUC__)
slouken@8582
   121
#define SDL_INLINE __inline__
slouken@8582
   122
#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
slouken@8582
   123
      defined(__DMC__) || defined(__SC__) || \
slouken@8582
   124
      defined(__WATCOMC__) || defined(__LCC__) || \
icculus@10925
   125
      defined(__DECC) || defined(__CC_ARM)
slouken@8582
   126
#define SDL_INLINE __inline
slouken@8582
   127
#ifndef __inline__
slouken@8582
   128
#define __inline__ __inline
slouken@8582
   129
#endif
slouken@8582
   130
#else
slouken@8582
   131
#define SDL_INLINE inline
slouken@8582
   132
#ifndef __inline__
slouken@8582
   133
#define __inline__ inline
slouken@8582
   134
#endif
slouken@8582
   135
#endif
slouken@8582
   136
#endif /* SDL_INLINE not defined */
slouken@8582
   137
slouken@8582
   138
#ifndef SDL_FORCE_INLINE
slouken@8582
   139
#if defined(_MSC_VER)
slouken@8582
   140
#define SDL_FORCE_INLINE __forceinline
slouken@8582
   141
#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
slouken@8582
   142
#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
slouken@8582
   143
#else
slouken@8582
   144
#define SDL_FORCE_INLINE static SDL_INLINE
slouken@8582
   145
#endif
slouken@8582
   146
#endif /* SDL_FORCE_INLINE not defined */
slouken@8582
   147
slouken@10616
   148
#ifndef SDL_NORETURN
slouken@10616
   149
#if defined(__GNUC__)
slouken@10616
   150
#define SDL_NORETURN __attribute__((noreturn))
slouken@10616
   151
#elif defined(_MSC_VER)
slouken@10616
   152
#define SDL_NORETURN __declspec(noreturn)
slouken@10616
   153
#else
slouken@10616
   154
#define SDL_NORETURN
slouken@10616
   155
#endif
slouken@10616
   156
#endif /* SDL_NORETURN not defined */
slouken@10616
   157
slouken@8582
   158
/* Apparently this is needed by several Windows compilers */
slouken@8582
   159
#if !defined(__MACH__)
slouken@8582
   160
#ifndef NULL
slouken@8582
   161
#ifdef __cplusplus
slouken@8582
   162
#define NULL 0
slouken@8582
   163
#else
slouken@8582
   164
#define NULL ((void *)0)
slouken@8582
   165
#endif
slouken@8582
   166
#endif /* NULL */
slouken@8582
   167
#endif /* ! Mac OS X - breaks precompiled headers */