[4.9.14] #define false 0 !?
X-G

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

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

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
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
X-G said:

because I got bit by this

Ah that must have been nasty...

Got to love template errors.

Peter Wang

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

Thread #601957. Printed from Allegro.cc