diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2013-06-20 03:04:01 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2013-06-20 03:04:01 +0000 |
commit | bd6a0ee94de111df08192719d6dec53d74f748de (patch) | |
tree | 1a65dbd3a8203cac9718251f3cb06a86f95e3488 /lib | |
parent | bb26dace180bb2bc0e52b9b63ab1a4521fedb9e8 (diff) | |
download | netpbm-mirror-bd6a0ee94de111df08192719d6dec53d74f748de.tar.gz netpbm-mirror-bd6a0ee94de111df08192719d6dec53d74f748de.tar.xz netpbm-mirror-bd6a0ee94de111df08192719d6dec53d74f748de.zip |
Use <stdbool.h> instead of locally defined bool
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1949 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/pm_c_util.h | 62 |
1 files changed, 38 insertions, 24 deletions
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])) |