curl-library
[PATCH] Use enum type for 'bool' on non-C99 platforms
From: Tor Arntsen <tor_at_spacetec.no>
Date: Wed, 26 May 2010 14:01:27 +0200
Date: Wed, 26 May 2010 14:01:27 +0200
An enum will catch non-bool assignments to bool on platforms with
a strict compiler, e.g MIPSPro.
--- (These comments below the above three dashes will not become part of comments proper if git-am is used.) Detailed explanation of the change: 1: 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms. 2: On non-C99 platforms there's no bool, so define an enum for that. 3: On C99 platforms 'false' and 'true' also exist. 4: Enum uses a global namespace though, so use bool_false and bool_true. 5: Use a define to let 'true' and 'false' use those enums. There are currently no use of true and false in libcurl proper, but there are some in the examples. This will cater for any later code happening to use true and false. 6: Redefine TRUE and FALSE too, to catch current use. 7: With this change, 'bool found = 1' will give a warning on MIPSPro, but 'bool found = TRUE' will not. 8: Change tested on IRIX/MIPSPro, AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too. lib/setup_once.h | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/setup_once.h b/lib/setup_once.h index cdc0ecf..84f90eb 100644 --- a/lib/setup_once.h +++ b/lib/setup_once.h @@ -261,11 +261,16 @@ struct timeval { /* - * Typedef to 'unsigned char' if bool is not an available 'typedefed' type. + * Typedef to enum if bool is not an available 'typedefed' type. */ #ifndef HAVE_BOOL_T -typedef unsigned char bool; + typedef enum { + bool_false = 0, + bool_true = 1 + } bool; +#define false bool_false +#define true bool_true #define HAVE_BOOL_T #endif @@ -275,10 +280,10 @@ typedef unsigned char bool; */ #ifndef TRUE -#define TRUE 1 +#define TRUE true #endif #ifndef FALSE -#define FALSE 0 +#define FALSE false #endif -- 1.7.1 --------------000806030900040501090903 Content-Type: text/x-patch; name="0001-Use-enum-type-for-bool-on-non-C99-platforms.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Use-enum-type-for-bool-on-non-C99-platforms.patch"Received on 2001-09-17