Patch: stdbool.h should be compatible with C++
Martin Buchholz
martin@xemacs.org
Sun Dec 5 19:43:00 GMT 1999
>>>>> "A" == Alexandre Oliva <oliva@lsd.ic.unicamp.br> writes:
A> On Dec 5, 1999, Martin Buchholz <martin@xemacs.org> wrote:
>> #define true 1
>> is clearer and Just Works.
A> Not in C++, in which `true' is expected to have type `bool', not
A> `int'.
Hmmmmm. I don't do much real C++ programming. My head is in C99 land.
OK, how about something along the lines of:
#ifdef __cplusplus
#define false false
#define true true
#else
#define false 0
#define true 1
#endif
Although that will only allow the C preprocessor, not the C++
preprocessor, to use `true' and `false' in expressions.
I don't know enough about C++ to see a way to achieve the same for
C++; perhaps it is not in the spirit of the C++ language.
Alternatively, perhaps
#include <stdbool.h>
could be interpreted as asking for C semantics for true and false. So
defining them to be 0 and 1 might be reasonable.
Another interpretation would be
#ifdef __cplusplus
/* do nothing */
#else
#define false 0
#define true 1
#endif
which is very likely close to what the user wants.
I leave it to the experts. The important thing is to get it right for
C.
Martin
More information about the Gcc-bugs
mailing list