I wrote a set of data structures and functions in C, some of which use the _Bool data type. When I started, the project was supposed to be pure C. Now I study using the C ++ based GUI toolkit and have done the internal code in the library.
However, when compiling the C ++ GUI, the compiler emits the following error:
ISO C++ forbids declaration of '_Bool' with no type
At first it seemed to me that I could find and replace _Bool with bool and create:
#ifndef MYBOOL_H #define MYBOOL_H typedef _Bool bool; #endif
and then in any headers that use _Bool
#ifdef __cplusplus extern "C" { #else #include "mybool.h" #endif
Until I realized that it would be collecting a library with one boolean (C _Bool) data type and linking to the library using another (C ++ bool). In practice, this may not be important, but theoretically it is possible (maybe some obscure system somewhere that makes the universe turn inside out).
I suppose I could just use int and use 0 for false and 1 for true, and typedef with something like typedef int mybool , but it seems unattractive.
Is there a better / idiomatic / standard way to do this?
c ++ c boolean
James Morris Aug 20 '10 at 9:57 2010-08-20 09:57
source share