mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
simplify booleans when <stdbool.h> header file is missing
This commit is contained in:
18
bool.h
18
bool.h
@@ -39,29 +39,25 @@
|
|||||||
/*
|
/*
|
||||||
* standard truth :-)
|
* standard truth :-)
|
||||||
*/
|
*/
|
||||||
#if !defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
#if !defined(HAVE_STDBOOL_H)
|
||||||
|
|
||||||
/* have a C99 compiler - we should have <stdbool.h>, true, false */
|
/* fake a <stdbool.h> header file */
|
||||||
|
typedef unsigned char bool; /* fake boolean value */
|
||||||
#elif !defined(__cplusplus)
|
|
||||||
|
|
||||||
/* do not have a C99 compiler - fake a <stdbool.h> header file */
|
|
||||||
typedef unsigned char bool;
|
|
||||||
#undef true
|
#undef true
|
||||||
#define true ((bool)(1))
|
#define true ((bool)(1))
|
||||||
#undef false
|
#undef false
|
||||||
#define false ((bool)(0))
|
#define false ((bool)(0))
|
||||||
|
|
||||||
#endif /* standard truth :-) */
|
#endif /* !HAVE_STDBOOL_H */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* calc historic booleans
|
* calc historic booleans
|
||||||
*/
|
*/
|
||||||
#undef TRUE
|
#undef TRUE
|
||||||
#define TRUE ((bool) true)
|
#define TRUE (true)
|
||||||
#undef FALSE
|
#undef FALSE
|
||||||
#define FALSE ((bool) false)
|
#define FALSE (false)
|
||||||
#undef BOOL
|
#undef BOOL
|
||||||
#define BOOL bool
|
#define BOOL bool
|
||||||
|
|
||||||
@@ -78,7 +74,7 @@ typedef unsigned char bool;
|
|||||||
* strtobool - convert a string to a boolean
|
* strtobool - convert a string to a boolean
|
||||||
*/
|
*/
|
||||||
#if !defined(strtobool)
|
#if !defined(strtobool)
|
||||||
#define strtobool(x) ((bool) ((x) != NULL && !strcmp((x), "true")))
|
#define strtobool(x) ((bool) ((x) != NULL && strcmp((x), "true") == 0))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user