Fixed bug #176
authorSam Lantinga <slouken@libsdl.org>
Thu, 13 Apr 2006 13:38:40 +0000
changeset 1626a80e1e0880b8
parent 1625 7e89aa7843c5
child 1627 aee7ea396f59
Fixed bug #176
[I'm fixing this for the public headers, but I'm not going to bother for the SDL library code (yet)]

To clarify: Normaly, GCC (or, to be precise, the preprocessor) will ignore
this, and compile the code happily. However, one can specify -Wundef to get a
warning about this.

One can probably argue whether to consider this a bug or not; but I think that
(a) from a semantic point of view, using "#if FOO" when FOO is not defined is
strange, and (b) since it is possible to trigger a warning about this, and a
trivial fix exists, it should be corrected.

I can think of two alternative patches, BTW:
1) Simply use #define HAVE_FOO 0, instead of not defining HAVE_FOO at all
2) Change
#if HAVE_FOO
to
#if HAVE_FOO+0
which always does the right thing.

But I think I still prefer the attached patch :-).
include/SDL_config_win32.h
include/SDL_stdinc.h
include/SDL_syswm.h
     1.1 --- a/include/SDL_config_win32.h	Thu Apr 13 13:30:21 2006 +0000
     1.2 +++ b/include/SDL_config_win32.h	Thu Apr 13 13:38:40 2006 +0000
     1.3 @@ -63,7 +63,7 @@
     1.4  
     1.5  /* Enabled for SDL 1.2 (binary compatibility) */
     1.6  #define HAVE_LIBC	1
     1.7 -#if HAVE_LIBC
     1.8 +#ifdef HAVE_LIBC
     1.9  /* Useful headers */
    1.10  #define HAVE_STDIO_H 1
    1.11  #define STDC_HEADERS 1
     2.1 --- a/include/SDL_stdinc.h	Thu Apr 13 13:30:21 2006 +0000
     2.2 +++ b/include/SDL_stdinc.h	Thu Apr 13 13:38:40 2006 +0000
     2.3 @@ -28,49 +28,47 @@
     2.4  #include "SDL_config.h"
     2.5  
     2.6  
     2.7 -#if HAVE_SYS_TYPES_H
     2.8 +#ifdef HAVE_SYS_TYPES_H
     2.9  #include <sys/types.h>
    2.10  #endif
    2.11 -#if HAVE_STDIO_H
    2.12 +#ifdef HAVE_STDIO_H
    2.13  #include <stdio.h>
    2.14  #endif
    2.15 -#if STDC_HEADERS
    2.16 +#if defined(STDC_HEADERS)
    2.17  # include <stdlib.h>
    2.18  # include <stddef.h>
    2.19  # include <stdarg.h>
    2.20  #else
    2.21 -# if HAVE_STDLIB_H
    2.22 -# include <stdlib.h>
    2.23 -# elif HAVE_MALLOC_H
    2.24 -# include <malloc.h>
    2.25 +# if defined(HAVE_STDLIB_H)
    2.26 +#  include <stdlib.h>
    2.27 +# elif defined(HAVE_MALLOC_H)
    2.28 +#  include <malloc.h>
    2.29  # endif
    2.30 -# if HAVE_STDDEF_H
    2.31 -# include <stddef.h>
    2.32 +# if defined(HAVE_STDDEF_H)
    2.33 +#  include <stddef.h>
    2.34  # endif
    2.35 -# if HAVE_STDARG_H
    2.36 -# include <stdarg.h>
    2.37 +# if defined(HAVE_STDARG_H)
    2.38 +#  include <stdarg.h>
    2.39  # endif
    2.40  #endif
    2.41 -#if HAVE_STRING_H
    2.42 -# if !STDC_HEADERS && HAVE_MEMORY_H
    2.43 -# include <memory.h>
    2.44 +#ifdef HAVE_STRING_H
    2.45 +# if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
    2.46 +#  include <memory.h>
    2.47  # endif
    2.48  # include <string.h>
    2.49  #endif
    2.50 -#if HAVE_STRINGS_H
    2.51 +#ifdef HAVE_STRINGS_H
    2.52  # include <strings.h>
    2.53  #endif
    2.54 -#if HAVE_INTTYPES_H
    2.55 +#if defined(HAVE_INTTYPES_H)
    2.56  # include <inttypes.h>
    2.57 -#else
    2.58 -# if HAVE_STDINT_H
    2.59 +#elif defined(HAVE_STDINT_H)
    2.60  # include <stdint.h>
    2.61 -# endif
    2.62  #endif
    2.63 -#if HAVE_CTYPE_H
    2.64 +#ifdef HAVE_CTYPE_H
    2.65  # include <ctype.h>
    2.66  #endif
    2.67 -#if HAVE_ICONV_H
    2.68 +#ifdef HAVE_ICONV_H
    2.69  # include <iconv.h>
    2.70  #endif
    2.71  
    2.72 @@ -138,32 +136,32 @@
    2.73  extern "C" {
    2.74  #endif
    2.75  
    2.76 -#if HAVE_MALLOC
    2.77 +#ifdef HAVE_MALLOC
    2.78  #define SDL_malloc	malloc
    2.79  #else
    2.80  extern DECLSPEC void * SDLCALL SDL_malloc(size_t size);
    2.81  #endif
    2.82  
    2.83 -#if HAVE_CALLOC
    2.84 +#ifdef HAVE_CALLOC
    2.85  #define SDL_calloc	calloc
    2.86  #else
    2.87  extern DECLSPEC void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
    2.88  #endif
    2.89  
    2.90 -#if HAVE_REALLOC
    2.91 +#ifdef HAVE_REALLOC
    2.92  #define SDL_realloc	realloc
    2.93  #else
    2.94  extern DECLSPEC void * SDLCALL SDL_realloc(void *mem, size_t size);
    2.95  #endif
    2.96  
    2.97 -#if HAVE_FREE
    2.98 +#ifdef HAVE_FREE
    2.99  #define SDL_free	free
   2.100  #else
   2.101  extern DECLSPEC void SDLCALL SDL_free(void *mem);
   2.102  #endif
   2.103  
   2.104 -#if HAVE_ALLOCA && !defined(alloca)
   2.105 -# if HAVE_ALLOCA_H
   2.106 +#if defined(HAVE_ALLOCA) && !defined(alloca)
   2.107 +# if defined(HAVE_ALLOCA_H)
   2.108  #  include <alloca.h>
   2.109  # elif defined(__GNUC__)
   2.110  #  define alloca __builtin_alloca
   2.111 @@ -176,7 +174,7 @@
   2.112     char *alloca ();
   2.113  # endif
   2.114  #endif
   2.115 -#if HAVE_ALLOCA
   2.116 +#ifdef HAVE_ALLOCA
   2.117  #define SDL_stack_alloc(type, count)    (type*)alloca(sizeof(type)*count)
   2.118  #define SDL_stack_free(data)
   2.119  #else
   2.120 @@ -184,26 +182,26 @@
   2.121  #define SDL_stack_free(data)            SDL_free(data)
   2.122  #endif
   2.123  
   2.124 -#if HAVE_GETENV
   2.125 +#ifdef HAVE_GETENV
   2.126  #define SDL_getenv	getenv
   2.127  #else
   2.128  extern DECLSPEC char * SDLCALL SDL_getenv(const char *name);
   2.129  #endif
   2.130  
   2.131 -#if HAVE_PUTENV
   2.132 +#ifdef HAVE_PUTENV
   2.133  #define SDL_putenv	putenv
   2.134  #else
   2.135  extern DECLSPEC int SDLCALL SDL_putenv(const char *variable);
   2.136  #endif
   2.137  
   2.138 -#if HAVE_QSORT
   2.139 +#ifdef HAVE_QSORT
   2.140  #define SDL_qsort	qsort
   2.141  #else
   2.142  extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
   2.143             int (*compare)(const void *, const void *));
   2.144  #endif
   2.145  
   2.146 -#if HAVE_ABS
   2.147 +#ifdef HAVE_ABS
   2.148  #define SDL_abs		abs
   2.149  #else
   2.150  #define SDL_abs(X)	((X) < 0 ? -(X) : (X))
   2.151 @@ -212,7 +210,7 @@
   2.152  #define SDL_min(x, y)	(((x) < (y)) ? (x) : (y))
   2.153  #define SDL_max(x, y)	(((x) > (y)) ? (x) : (y))
   2.154  
   2.155 -#if HAVE_CTYPE_H
   2.156 +#ifdef HAVE_CTYPE_H
   2.157  #define SDL_isdigit(X)  isdigit(X)
   2.158  #define SDL_isspace(X)  isspace(X)
   2.159  #define SDL_toupper(X)  toupper(X)
   2.160 @@ -224,7 +222,7 @@
   2.161  #define SDL_tolower(X)  (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X))
   2.162  #endif
   2.163  
   2.164 -#if HAVE_MEMSET
   2.165 +#ifdef HAVE_MEMSET
   2.166  #define SDL_memset      memset
   2.167  #else
   2.168  extern DECLSPEC void * SDLCALL SDL_memset(void *dst, int c, size_t len);
   2.169 @@ -279,9 +277,9 @@
   2.170  } while(0)
   2.171  #endif
   2.172  #ifndef SDL_memcpy
   2.173 -#if HAVE_MEMCPY
   2.174 +#ifdef HAVE_MEMCPY
   2.175  #define SDL_memcpy      memcpy
   2.176 -#elif HAVE_BCOPY
   2.177 +#elif defined(HAVE_BCOPY)
   2.178  #define SDL_memcpy(d, s, n)	bcopy((s), (d), (n))
   2.179  #else
   2.180  extern DECLSPEC void * SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
   2.181 @@ -334,9 +332,9 @@
   2.182  extern DECLSPEC void * SDLCALL SDL_revcpy(void *dst, const void *src, size_t len);
   2.183  #endif
   2.184  
   2.185 -#if HAVE_MEMMOVE
   2.186 +#ifdef HAVE_MEMMOVE
   2.187  #define SDL_memmove     memmove
   2.188 -#elif HAVE_BCOPY
   2.189 +#elif defined(HAVE_BCOPY)
   2.190  #define SDL_memmove(d, s, n)	bcopy((s), (d), (n))
   2.191  #else
   2.192  #define SDL_memmove(dst, src, len)			\
   2.193 @@ -349,133 +347,133 @@
   2.194  } while(0)
   2.195  #endif
   2.196  
   2.197 -#if HAVE_MEMCMP
   2.198 +#ifdef HAVE_MEMCMP
   2.199  #define SDL_memcmp      memcmp
   2.200  #else
   2.201  extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
   2.202  #endif
   2.203  
   2.204 -#if HAVE_STRLEN
   2.205 +#ifdef HAVE_STRLEN
   2.206  #define SDL_strlen      strlen
   2.207  #else
   2.208  extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
   2.209  #endif
   2.210  
   2.211 -#if HAVE_STRLCPY
   2.212 +#ifdef HAVE_STRLCPY
   2.213  #define SDL_strlcpy     strlcpy
   2.214  #else
   2.215  extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
   2.216  #endif
   2.217  
   2.218 -#if HAVE_STRLCAT
   2.219 +#ifdef HAVE_STRLCAT
   2.220  #define SDL_strlcat    strlcat
   2.221  #else
   2.222  extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
   2.223  #endif
   2.224  
   2.225 -#if HAVE_STRDUP
   2.226 +#ifdef HAVE_STRDUP
   2.227  #define SDL_strdup     strdup
   2.228  #else
   2.229  extern DECLSPEC char * SDLCALL SDL_strdup(const char *string);
   2.230  #endif
   2.231  
   2.232 -#if HAVE__STRREV
   2.233 +#ifdef HAVE__STRREV
   2.234  #define SDL_strrev      _strrev
   2.235  #else
   2.236  extern DECLSPEC char * SDLCALL SDL_strrev(char *string);
   2.237  #endif
   2.238  
   2.239 -#if HAVE__STRUPR
   2.240 +#ifdef HAVE__STRUPR
   2.241  #define SDL_strupr      _strupr
   2.242  #else
   2.243  extern DECLSPEC char * SDLCALL SDL_strupr(char *string);
   2.244  #endif
   2.245  
   2.246 -#if HAVE__STRLWR
   2.247 +#ifdef HAVE__STRLWR
   2.248  #define SDL_strlwr      _strlwr
   2.249  #else
   2.250  extern DECLSPEC char * SDLCALL SDL_strlwr(char *string);
   2.251  #endif
   2.252  
   2.253 -#if HAVE_STRCHR
   2.254 +#ifdef HAVE_STRCHR
   2.255  #define SDL_strchr      strchr
   2.256 -#elif HAVE_INDEX
   2.257 +#elif defined(HAVE_INDEX)
   2.258  #define SDL_strchr      index
   2.259  #else
   2.260  extern DECLSPEC char * SDLCALL SDL_strchr(const char *string, int c);
   2.261  #endif
   2.262  
   2.263 -#if HAVE_STRRCHR
   2.264 +#ifdef HAVE_STRRCHR
   2.265  #define SDL_strrchr     strrchr
   2.266 -#elif HAVE_RINDEX
   2.267 +#elif defined(HAVE_RINDEX)
   2.268  #define SDL_strrchr     rindex
   2.269  #else
   2.270  extern DECLSPEC char * SDLCALL SDL_strrchr(const char *string, int c);
   2.271  #endif
   2.272  
   2.273 -#if HAVE_STRSTR
   2.274 +#ifdef HAVE_STRSTR
   2.275  #define SDL_strstr      strstr
   2.276  #else
   2.277  extern DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
   2.278  #endif
   2.279  
   2.280 -#if HAVE_ITOA
   2.281 +#ifdef HAVE_ITOA
   2.282  #define SDL_itoa        itoa
   2.283  #else
   2.284  #define SDL_itoa(value, string, radix)	SDL_ltoa((long)value, string, radix)
   2.285  #endif
   2.286  
   2.287 -#if HAVE__LTOA
   2.288 +#ifdef HAVE__LTOA
   2.289  #define SDL_ltoa        _ltoa
   2.290  #else
   2.291  extern DECLSPEC char * SDLCALL SDL_ltoa(long value, char *string, int radix);
   2.292  #endif
   2.293  
   2.294 -#if HAVE__UITOA
   2.295 +#ifdef HAVE__UITOA
   2.296  #define SDL_uitoa       _uitoa
   2.297  #else
   2.298  #define SDL_uitoa(value, string, radix)	SDL_ultoa((long)value, string, radix)
   2.299  #endif
   2.300  
   2.301 -#if HAVE__ULTOA
   2.302 +#ifdef HAVE__ULTOA
   2.303  #define SDL_ultoa       _ultoa
   2.304  #else
   2.305  extern DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *string, int radix);
   2.306  #endif
   2.307  
   2.308 -#if HAVE_STRTOL
   2.309 +#ifdef HAVE_STRTOL
   2.310  #define SDL_strtol      strtol
   2.311  #else
   2.312  extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, int base);
   2.313  #endif
   2.314  
   2.315 -#if HAVE_STRTOUL
   2.316 +#ifdef HAVE_STRTOUL
   2.317  #define SDL_strtoul      strtoul
   2.318  #else
   2.319  extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string, char **endp, int base);
   2.320  #endif
   2.321  
   2.322 -#if SDL_HAS_64BIT_TYPE
   2.323 +#ifdef SDL_HAS_64BIT_TYPE
   2.324  
   2.325 -#if HAVE__I64TOA
   2.326 +#ifdef HAVE__I64TOA
   2.327  #define SDL_lltoa       _i64toa
   2.328  #else
   2.329  extern DECLSPEC char* SDLCALL SDL_lltoa(Sint64 value, char *string, int radix);
   2.330  #endif
   2.331  
   2.332 -#if HAVE__UI64TOA
   2.333 +#ifdef HAVE__UI64TOA
   2.334  #define SDL_ulltoa      _ui64toa
   2.335  #else
   2.336  extern DECLSPEC char* SDLCALL SDL_ulltoa(Uint64 value, char *string, int radix);
   2.337  #endif
   2.338  
   2.339 -#if HAVE_STRTOLL
   2.340 +#ifdef HAVE_STRTOLL
   2.341  #define SDL_strtoll     strtoll
   2.342  #else
   2.343  extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, int base);
   2.344  #endif
   2.345  
   2.346 -#if HAVE_STRTOULL
   2.347 +#ifdef HAVE_STRTOULL
   2.348  #define SDL_strtoull     strtoull
   2.349  #else
   2.350  extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp, int base);
   2.351 @@ -483,65 +481,65 @@
   2.352  
   2.353  #endif /* SDL_HAS_64BIT_TYPE */
   2.354  
   2.355 -#if HAVE_STRTOD
   2.356 +#ifdef HAVE_STRTOD
   2.357  #define SDL_strtod      strtod
   2.358  #else
   2.359  extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp);
   2.360  #endif
   2.361  
   2.362 -#if HAVE_ATOI
   2.363 +#ifdef HAVE_ATOI
   2.364  #define SDL_atoi        atoi
   2.365  #else
   2.366  #define SDL_atoi(X)     SDL_strtol(X, NULL, 0)
   2.367  #endif
   2.368  
   2.369 -#if HAVE_ATOF
   2.370 +#ifdef HAVE_ATOF
   2.371  #define SDL_atof        atof
   2.372  #else
   2.373  #define SDL_atof(X)     SDL_strtod(X, NULL)
   2.374  #endif
   2.375  
   2.376 -#if HAVE_STRCMP
   2.377 +#ifdef HAVE_STRCMP
   2.378  #define SDL_strcmp      strcmp
   2.379  #else
   2.380  extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
   2.381  #endif
   2.382  
   2.383 -#if HAVE_STRNCMP
   2.384 +#ifdef HAVE_STRNCMP
   2.385  #define SDL_strncmp     strncmp
   2.386  #else
   2.387  extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
   2.388  #endif
   2.389  
   2.390 -#if HAVE_STRCASECMP
   2.391 +#ifdef HAVE_STRCASECMP
   2.392  #define SDL_strcasecmp  strcasecmp
   2.393 -#elif HAVE__STRICMP
   2.394 +#elif defined(HAVE__STRICMP)
   2.395  #define SDL_strcasecmp  _stricmp
   2.396  #else
   2.397  extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
   2.398  #endif
   2.399  
   2.400 -#if HAVE_STRNCASECMP
   2.401 +#ifdef HAVE_STRNCASECMP
   2.402  #define SDL_strncasecmp strncasecmp
   2.403 -#elif HAVE__STRNICMP
   2.404 +#elif defined(HAVE__STRNICMP)
   2.405  #define SDL_strncasecmp _strnicmp
   2.406  #else
   2.407  extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
   2.408  #endif
   2.409  
   2.410 -#if HAVE_SSCANF
   2.411 +#ifdef HAVE_SSCANF
   2.412  #define SDL_sscanf      sscanf
   2.413  #else
   2.414  extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
   2.415  #endif
   2.416  
   2.417 -#if HAVE_SNPRINTF
   2.418 +#ifdef HAVE_SNPRINTF
   2.419  #define SDL_snprintf    snprintf
   2.420  #else
   2.421  extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
   2.422  #endif
   2.423  
   2.424 -#if HAVE_VSNPRINTF
   2.425 +#ifdef HAVE_VSNPRINTF
   2.426  #define SDL_vsnprintf   vsnprintf
   2.427  #else
   2.428  extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
   2.429 @@ -553,7 +551,7 @@
   2.430  #define SDL_ICONV_EILSEQ	(size_t)-3
   2.431  #define SDL_ICONV_EINVAL	(size_t)-4
   2.432  
   2.433 -#if HAVE_ICONV
   2.434 +#ifdef HAVE_ICONV
   2.435  #define SDL_iconv_t     iconv_t
   2.436  #define SDL_iconv_open  iconv_open
   2.437  #define SDL_iconv_close iconv_close
     3.1 --- a/include/SDL_syswm.h	Thu Apr 13 13:30:21 2006 +0000
     3.2 +++ b/include/SDL_syswm.h	Thu Apr 13 13:38:40 2006 +0000
     3.3 @@ -46,7 +46,7 @@
     3.4  #else
     3.5  
     3.6  /* This is the structure for custom window manager events */
     3.7 -#if SDL_VIDEO_DRIVER_X11
     3.8 +#if defined(SDL_VIDEO_DRIVER_X11)
     3.9  #if defined(__APPLE__) && defined(__MACH__)
    3.10  /* conflicts with Quickdraw.h */
    3.11  #define Cursor X11Cursor
    3.12 @@ -100,7 +100,7 @@
    3.13  	} info;
    3.14  } SDL_SysWMinfo;
    3.15  
    3.16 -#elif SDL_VIDEO_DRIVER_NANOX
    3.17 +#elif defined(SDL_VIDEO_DRIVER_NANOX)
    3.18  #include <microwin/nano-X.h>
    3.19  
    3.20  /* The generic custom event structure */
    3.21 @@ -115,7 +115,7 @@
    3.22  	GR_WINDOW_ID window ;	/* The display window */
    3.23  } SDL_SysWMinfo;
    3.24  
    3.25 -#elif SDL_VIDEO_DRIVER_WINDIB || SDL_VIDEO_DRIVER_DDRAW
    3.26 +#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW)
    3.27  #define WIN32_LEAN_AND_MEAN
    3.28  #include <windows.h>
    3.29  
    3.30 @@ -135,7 +135,7 @@
    3.31  	HGLRC hglrc;			/* The OpenGL context, if any */
    3.32  } SDL_SysWMinfo;
    3.33  
    3.34 -#elif SDL_VIDEO_DRIVER_RISCOS
    3.35 +#elif defined(SDL_VIDEO_DRIVER_RISCOS)
    3.36  
    3.37  /* RISC OS custom event structure */
    3.38  struct SDL_SysWMmsg {
    3.39 @@ -152,7 +152,7 @@
    3.40  	int window;		/* The RISC OS display window */
    3.41  } SDL_SysWMinfo;
    3.42  
    3.43 -#elif SDL_VIDEO_DRIVER_PHOTON
    3.44 +#elif defined(SDL_VIDEO_DRIVER_PHOTON)
    3.45  #include <sys/neutrino.h>
    3.46  #include <Ph.h>
    3.47