diff options
-rw-r--r-- | doc/HISTORY | 2 | ||||
-rw-r--r-- | lib/util/pm_c_util.h | 62 |
2 files changed, 40 insertions, 24 deletions
diff --git a/doc/HISTORY b/doc/HISTORY index 331eb316..4edce4fc 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -79,6 +79,8 @@ not yet BJH Release 10.63.00 install: fix Perl warning in installnetpbm. Broken in Netpbm 10.61. + build: Use <stdbool.h> when available. + build: fix problem with creating lib/util that already exists. Broken in Netpbm 10.62. diff --git a/lib/util/pm_c_util.h b/lib/util/pm_c_util.h index f17d1e03..79897cf0 100644 --- a/lib/util/pm_c_util.h +++ b/lib/util/pm_c_util.h @@ -41,35 +41,49 @@ use "int". */ -/* We used to assume that if TRUE was defined, then bool was too. - However, we had a report on 2001.09.21 of a Tru64 system that had - TRUE but not bool and on 2002.03.21 of an AIX 4.3 system that was - likewise. So now we define bool all the time, unless the macro - HAVE_BOOL is defined. If someone is using the Netpbm libraries and - also another library that defines bool, he can either make the - other library define/respect HAVE_BOOL or just define HAVE_BOOL in - the file that includes pm_config.h or with a compiler option. Note - that C++ always has bool. +/* We will probably never again see a system that does not have + <stdbool.h>, but just in case, we have our own alternative here. - A preferred way of getting booleans is <stdbool.h>. But it's not - available on all platforms, and it's easy to reproduce what it does - here. + Evidence shows that the compiler actually produces better code with + <stdbool.h> than with bool simply typedefed to int. */ + +#ifdef __cplusplus + /* C++ has a bool type and false and true constants built in. */ +#else + /* The test for __STDC__ is paranoid. It is there just in case some + nonstandard compiler defines __STDC_VERSION__ in an arbitrary manner. + */ + #if ( defined(__GNUC__) && (__GNUC__ >= 3) ) || \ + ( defined(__STDC__) && (__STDC__ ==1) && \ + defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ) + #include <stdbool.h> + #else + /* We used to assume that if TRUE was defined, then bool was too. + However, we had a report on 2001.09.21 of a Tru64 system that had + TRUE but not bool and on 2002.03.21 of an AIX 4.3 system that was + likewise. So now we define bool all the time, unless the macro + HAVE_BOOL is defined. If someone is using the Netpbm libraries and + also another library that defines bool, he can either make the + other library define/respect HAVE_BOOL or just define HAVE_BOOL in + the file that includes pm_config.h or with a compiler option. Note + that C++ always has bool. + */ + #ifndef HAVE_BOOL + #define HAVE_BOOL 1 + typedef int bool; + #endif + #ifndef true + enum boolvalue {false=0, true=1}; + #endif + #endif +#endif + #ifndef TRUE - #define TRUE 1 + #define TRUE true #endif #ifndef FALSE - #define FALSE 0 - #endif -/* C++ has a bool type and false and true constants built in. */ -#ifndef __cplusplus - #ifndef HAVE_BOOL - #define HAVE_BOOL 1 - typedef int bool; - #endif - #ifndef true - enum boolvalue {false=0, true=1}; - #endif +#define FALSE false #endif #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) |