From bd6a0ee94de111df08192719d6dec53d74f748de Mon Sep 17 00:00:00 2001 From: giraffedata Date: Thu, 20 Jun 2013 03:04:01 +0000 Subject: Use instead of locally defined bool git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1949 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/util/pm_c_util.h | 62 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 24 deletions(-) (limited to 'lib/util/pm_c_util.h') 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 + , but just in case, we have our own alternative here. - A preferred way of getting booleans is . 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 + 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 + #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])) -- cgit 1.4.1