|
[4.9.14] #define false 0 !? |
X-G
Member #856
December 2000
|
astdbool.h does this: # define bool _Bool # define false 0 # define true 1 This is not a good idea. It means using Allegro in C++ applications becomes hazardous to impossible, as it breaks overload resolution and template specialization involving bools; false and true are now ints rather than bools, which match differently (for instance, in MSVC9, the integer constant 0 matches pointers better [or at least as good as] than it matches bools, so a function overloaded on bool and char* will have the latter version chosen when you pass true or false to it). Patch is simple; just wrap it in #ifndef __cplusplus so that these defines don't exist for C++ applications: #ifndef __cplusplus # define bool _Bool # define false 0 # define true 1 #endif
-- |
Elias
Member #358
May 2000
|
There's also this comment above: /* This code is recommended by the autoconf manual */
Which almost implies it's a very bad idea... And I wonder if we still support any compiler where stdbool.h doesn't exist anyway... -- |
X-G
Member #856
December 2000
|
Well, as mentioned, on MSVC9 at least the aforementioned defines got defined (the reason I'm posting is of course because I got bit by this ), implying ALLEGRO_HAVE_STDBOOL_H was not defined... -- |
Oscar Giner
Member #2,207
April 2002
|
ImLeftFooted
Member #3,935
October 2003
|
|
Peter Wang
Member #23
April 2000
|
I've changed it to this, so astdbool.h does nothing in C++. I don't see any reason to define _Bool in C++. #ifndef __cplusplus # ifdef ALLEGRO_HAVE_STDBOOL_H # include <stdbool.h> # else # ifndef ALLEGRO_HAVE__BOOL typedef unsigned char _Bool; # endif # define bool _Bool # define false 0 # define true 1 # define __bool_true_false_are_defined 1 # endif #endif
|
|