Mercurial > sdl-ios-xcode
comparison include/SDL_stdinc.h @ 1381:8570e1f4b1f1
On FreeBSD, alloca is defined in stdlib.h
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 20 Feb 2006 02:30:15 +0000 |
parents | c0a74f199ecf |
children | d910939febfa |
comparison
equal
deleted
inserted
replaced
1380:d94b080ff6ce | 1381:8570e1f4b1f1 |
---|---|
25 #ifndef _SDL_stdinc_h | 25 #ifndef _SDL_stdinc_h |
26 #define _SDL_stdinc_h | 26 #define _SDL_stdinc_h |
27 | 27 |
28 #include "SDL_config.h" | 28 #include "SDL_config.h" |
29 | 29 |
30 /* AIX requires this to be the first thing in the file. */ | 30 |
31 #if HAVE_ALLOCA | 31 #if HAVE_SYS_TYPES_H |
32 #include <sys/types.h> | |
33 #endif | |
34 #if HAVE_STDIO_H | |
35 #include <stdio.h> | |
36 #endif | |
37 #if STDC_HEADERS | |
38 # include <stdlib.h> | |
39 # include <stddef.h> | |
40 # include <stdarg.h> | |
41 #else | |
42 # if HAVE_STDLIB_H | |
43 # include <stdlib.h> | |
44 # elif HAVE_MALLOC_H | |
45 # include <malloc.h> | |
46 # endif | |
47 # if HAVE_STDARG_H | |
48 # include <stdarg.h> | |
49 # endif | |
50 #endif | |
51 #if HAVE_STRING_H | |
52 # if !STDC_HEADERS && HAVE_MEMORY_H | |
53 # include <memory.h> | |
54 # endif | |
55 # include <string.h> | |
56 #endif | |
57 #if HAVE_STRINGS_H | |
58 # include <strings.h> | |
59 #endif | |
60 #if HAVE_INTTYPES_H | |
61 # include <inttypes.h> | |
62 #else | |
63 # if HAVE_STDINT_H | |
64 # include <stdint.h> | |
65 # endif | |
66 #endif | |
67 #if HAVE_CTYPE_H | |
68 # include <ctype.h> | |
69 #endif | |
70 | |
71 /* The number of elements in an array */ | |
72 #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0])) | |
73 #define SDL_TABLESIZE(table) SDL_arraysize(table) | |
74 | |
75 /* Basic data types */ | |
76 typedef enum SDL_bool { | |
77 SDL_FALSE = 0, | |
78 SDL_TRUE = 1 | |
79 } SDL_bool; | |
80 | |
81 typedef int8_t Sint8; | |
82 typedef uint8_t Uint8; | |
83 typedef int16_t Sint16; | |
84 typedef uint16_t Uint16; | |
85 typedef int32_t Sint32; | |
86 typedef uint32_t Uint32; | |
87 | |
88 #ifdef SDL_HAS_64BIT_TYPE | |
89 typedef int64_t Sint64; | |
90 typedef uint64_t Uint64; | |
91 #else | |
92 /* This is really just a hack to prevent the compiler from complaining */ | |
93 typedef struct { | |
94 Uint32 hi; | |
95 Uint32 lo; | |
96 } Uint64, Sint64; | |
97 #endif | |
98 | |
99 /* Make sure the types really have the right sizes */ | |
100 #define SDL_COMPILE_TIME_ASSERT(name, x) \ | |
101 typedef int SDL_dummy_ ## name[(x) * 2 - 1] | |
102 | |
103 SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1); | |
104 SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1); | |
105 SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2); | |
106 SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2); | |
107 SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4); | |
108 SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4); | |
109 SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8); | |
110 SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); | |
111 | |
112 /* Check to make sure enums are the size of ints, for structure packing. | |
113 For both Watcom C/C++ and Borland C/C++ the compiler option that makes | |
114 enums having the size of an int must be enabled. | |
115 This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11). | |
116 */ | |
117 /* Enable enums always int in CodeWarrior (for MPW use "-enum int") */ | |
118 #ifdef __MWERKS__ | |
119 #pragma enumsalwaysint on | |
120 #endif | |
121 | |
122 typedef enum { | |
123 DUMMY_ENUM_VALUE | |
124 } SDL_DUMMY_ENUM; | |
125 | |
126 SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int)); | |
127 | |
128 | |
129 #include "begin_code.h" | |
130 /* Set up for C function definitions, even when using C++ */ | |
131 #ifdef __cplusplus | |
132 extern "C" { | |
133 #endif | |
134 | |
135 #if HAVE_MALLOC | |
136 #define SDL_malloc malloc | |
137 #else | |
138 extern DECLSPEC void * SDLCALL SDL_malloc(size_t size); | |
139 #endif | |
140 | |
141 #if HAVE_CALLOC | |
142 #define SDL_calloc calloc | |
143 #else | |
144 extern DECLSPEC void * SDLCALL SDL_calloc(size_t nmemb, size_t size); | |
145 #endif | |
146 | |
147 #if HAVE_REALLOC | |
148 #define SDL_realloc realloc | |
149 #else | |
150 extern DECLSPEC void * SDLCALL SDL_realloc(void *mem, size_t size); | |
151 #endif | |
152 | |
153 #if HAVE_FREE | |
154 #define SDL_free free | |
155 #else | |
156 extern DECLSPEC void SDLCALL SDL_free(void *mem); | |
157 #endif | |
158 | |
159 #if HAVE_ALLOCA && !defined(alloca) | |
32 # if HAVE_ALLOCA_H | 160 # if HAVE_ALLOCA_H |
33 # include <alloca.h> | 161 # include <alloca.h> |
34 # elif __GNUC__ | 162 # elif __GNUC__ |
35 # define alloca __builtin_alloca | 163 # define alloca __builtin_alloca |
36 # elif _MSC_VER | 164 # elif _MSC_VER |
37 # include <malloc.h> | 165 # include <malloc.h> |
38 # define alloca _alloca | 166 # define alloca _alloca |
39 # elif _AIX | 167 # elif _AIX |
40 #pragma alloca | 168 #pragma alloca |
41 # else | 169 # else |
42 # ifndef alloca /* predefined by HP cc +Olibcalls */ | 170 char *alloca (); |
43 char *alloca (); | |
44 # endif | |
45 # endif | 171 # endif |
46 #endif | 172 #endif |
47 | |
48 #if HAVE_SYS_TYPES_H | |
49 #include <sys/types.h> | |
50 #endif | |
51 #if HAVE_STDIO_H | |
52 #include <stdio.h> | |
53 #endif | |
54 #if STDC_HEADERS | |
55 # include <stdlib.h> | |
56 # include <stddef.h> | |
57 # include <stdarg.h> | |
58 #else | |
59 # if HAVE_STDLIB_H | |
60 # include <stdlib.h> | |
61 # elif HAVE_MALLOC_H | |
62 # include <malloc.h> | |
63 # endif | |
64 # if HAVE_STDARG_H | |
65 # include <stdarg.h> | |
66 # endif | |
67 #endif | |
68 #if HAVE_STRING_H | |
69 # if !STDC_HEADERS && HAVE_MEMORY_H | |
70 # include <memory.h> | |
71 # endif | |
72 # include <string.h> | |
73 #endif | |
74 #if HAVE_STRINGS_H | |
75 # include <strings.h> | |
76 #endif | |
77 #if HAVE_INTTYPES_H | |
78 # include <inttypes.h> | |
79 #else | |
80 # if HAVE_STDINT_H | |
81 # include <stdint.h> | |
82 # endif | |
83 #endif | |
84 #if HAVE_CTYPE_H | |
85 # include <ctype.h> | |
86 #endif | |
87 | |
88 /* The number of elements in an array */ | |
89 #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0])) | |
90 #define SDL_TABLESIZE(table) SDL_arraysize(table) | |
91 | |
92 /* Basic data types */ | |
93 typedef enum SDL_bool { | |
94 SDL_FALSE = 0, | |
95 SDL_TRUE = 1 | |
96 } SDL_bool; | |
97 | |
98 typedef int8_t Sint8; | |
99 typedef uint8_t Uint8; | |
100 typedef int16_t Sint16; | |
101 typedef uint16_t Uint16; | |
102 typedef int32_t Sint32; | |
103 typedef uint32_t Uint32; | |
104 | |
105 #ifdef SDL_HAS_64BIT_TYPE | |
106 typedef int64_t Sint64; | |
107 typedef uint64_t Uint64; | |
108 #else | |
109 /* This is really just a hack to prevent the compiler from complaining */ | |
110 typedef struct { | |
111 Uint32 hi; | |
112 Uint32 lo; | |
113 } Uint64, Sint64; | |
114 #endif | |
115 | |
116 /* Make sure the types really have the right sizes */ | |
117 #define SDL_COMPILE_TIME_ASSERT(name, x) \ | |
118 typedef int SDL_dummy_ ## name[(x) * 2 - 1] | |
119 | |
120 SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1); | |
121 SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1); | |
122 SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2); | |
123 SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2); | |
124 SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4); | |
125 SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4); | |
126 SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8); | |
127 SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); | |
128 | |
129 /* Check to make sure enums are the size of ints, for structure packing. | |
130 For both Watcom C/C++ and Borland C/C++ the compiler option that makes | |
131 enums having the size of an int must be enabled. | |
132 This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11). | |
133 */ | |
134 /* Enable enums always int in CodeWarrior (for MPW use "-enum int") */ | |
135 #ifdef __MWERKS__ | |
136 #pragma enumsalwaysint on | |
137 #endif | |
138 | |
139 typedef enum { | |
140 DUMMY_ENUM_VALUE | |
141 } SDL_DUMMY_ENUM; | |
142 | |
143 SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int)); | |
144 | |
145 | |
146 #include "begin_code.h" | |
147 /* Set up for C function definitions, even when using C++ */ | |
148 #ifdef __cplusplus | |
149 extern "C" { | |
150 #endif | |
151 | |
152 #if HAVE_MALLOC | |
153 #define SDL_malloc malloc | |
154 #else | |
155 extern DECLSPEC void * SDLCALL SDL_malloc(size_t size); | |
156 #endif | |
157 | |
158 #if HAVE_CALLOC | |
159 #define SDL_calloc calloc | |
160 #else | |
161 extern DECLSPEC void * SDLCALL SDL_calloc(size_t nmemb, size_t size); | |
162 #endif | |
163 | |
164 #if HAVE_REALLOC | |
165 #define SDL_realloc realloc | |
166 #else | |
167 extern DECLSPEC void * SDLCALL SDL_realloc(void *mem, size_t size); | |
168 #endif | |
169 | |
170 #if HAVE_FREE | |
171 #define SDL_free free | |
172 #else | |
173 extern DECLSPEC void SDLCALL SDL_free(void *mem); | |
174 #endif | |
175 | |
176 #if HAVE_ALLOCA | 173 #if HAVE_ALLOCA |
177 #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*count) | 174 #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*count) |
178 #define SDL_stack_free(data) | 175 #define SDL_stack_free(data) |
179 #else | 176 #else |
180 #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*count) | 177 #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*count) |