| Summary: | SDL_stdinc.h uses #if when it should be using #ifdef | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Max Horn <max> |
| Component: | *don't know* | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | HG 1.2 | ||
| Hardware: | All | ||
| OS: | Other | ||
| Attachments: | Patch for SDL_stdinc.h | ||
|
Description
Max Horn
2006-03-22 12:31:14 UTC
Created attachment 89 [details]
Patch for SDL_stdinc.h
What compiler do you have that doesn't accept that? All the compilers I've seen have the following behavior foo not defined #if foo -> FALSE #undef foo #if foo -> FALSE #define foo 0 #if foo -> FALSE #define foo 1 #if foo -> TRUE For the record, if you look at the autoconf configure tests, they use exactly the same convention: # Factoring default headers for most tests. ac_includes_default="\ #include <stdio.h> #if HAVE_SYS_TYPES_H # include <sys/types.h> #endif #if HAVE_SYS_STAT_H # include <sys/stat.h> #endif #if STDC_HEADERS # include <stdlib.h> # include <stddef.h> #else ... 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 :-). This patch (and a couple cases you missed) is in CVS. Thanks! |