Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » [4.9.14] #define false 0 !?

This thread is locked; no one can reply to it. rss feed Print
[4.9.14] #define false 0 !?
X-G
Member #856
December 2000
avatar

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

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

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...

--
"Either help out or stop whining" - Evert

X-G
Member #856
December 2000
avatar

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...

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Oscar Giner
Member #2,207
April 2002
avatar

Elias said:

And I wonder if we still support any compiler where stdbool.h doesn't exist anyway...

MSVC 9 doesn't have stdbool.h. It's a C99 header and MSVC is'nt a C99 compiler.

ImLeftFooted
Member #3,935
October 2003
avatar

X-G said:

because I got bit by this

Ah that must have been nasty...

Got to love template errors.

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

Go to: