diff options
Diffstat (limited to 'nuttx/include/stdbool.h')
-rw-r--r-- | nuttx/include/stdbool.h | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/nuttx/include/stdbool.h b/nuttx/include/stdbool.h index f11219912..9c16aee29 100644 --- a/nuttx/include/stdbool.h +++ b/nuttx/include/stdbool.h @@ -42,10 +42,33 @@ #include <nuttx/config.h> +/* If CONFIG_ARCH_STDBOOL_H is set, then the archecture will provide its own + * stdbool.h file. In this case, this header file will simply re-direct to + * the architecture-specfiic stdbool.h header file. + */ + #ifdef CONFIG_ARCH_STDBOOL_H # include <arch/stdbool.h> + +/* NuttX will insist that the sizeof(bool) is 8-bits. The sizeof of _Bool + * used by any specific compiler is implementation specific: It can vary from + * compiler-to-compiler and even vary between different versions of the same + * compiler. Compilers seems to be converging to sizeof(_Bool) == 1. If that + * is true for your compiler, you should define CONFIG_C99_BOOL8 in your NuttX + * configuration for better standards compatibility. + * + * CONFIG_C99_BOOL8 - Means (1) your C++ compiler has sizeof(_Bool) == 8, + * (2) your C compiler supports the C99 _Bool intrinsic type, and (2) that + * the C99 _Bool type also has size 1. + */ + #else + + /* nuttx/compiler.h may also define or undefine CONFIG_C99_BOOL8 */ + # include <nuttx/compiler.h> + +#if !defined(__cplusplus) || !defined(CONFIG_C99_BOOL8) # include <stdint.h> /**************************************************************************** @@ -58,10 +81,15 @@ * NOTE: Under C99 'bool' is required to be defined to be the intrinsic type * _Bool. However, in this NuttX context, we need backward compatibility * to pre-C99 standards where _Bool is not an intrinsic type. Hence, we - * use _Bool8 as the underlying type. + * use _Bool8 as the underlying type (unless CONFIG_C99_BOOL8 is defined) */ -#define bool _Bool8 +#ifdef CONFIG_C99_BOOL8 +# define bool _Bool +#else +# define bool _Bool8 +#endif + #define true 1 #define false 0 @@ -83,7 +111,10 @@ * as the underlying type. */ +#ifndef CONFIG_C99_BOOL8 typedef uint8_t _Bool8; +#endif +#endif /* __cplusplus && CONFIG_C99_BOOL8 */ #endif /* CONFIG_ARCH_STDBOOL_H */ #endif /* __INCLUDE_STDBOOL_H */ |