Re: [AD] bool in MSVC

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2010-03-24, Evert Glebbeek <eglebbk@xxxxxxxxxx> wrote:
> On 24 Mar 2010, at 21:48 , Milan Mimica wrote:
> > There is a problem with expressions like:
> > (onoff == (display->flags & ALLEGRO_FULLSCREEN_WINDOW))
> > 
> > in MSVC, bool is defined to unsigned char and ALLEGRO_FULLSCREEN_WINDOW is 512.
> > 
> > (flags & 512) evaluates to 512
> > (boo)(flags & 512) evaluates to false
> 
> I'm not sure what "onoff" is supposed to be in that expression, but
> since the right hand side works out to an integer (it's a logical and)
> it is a bug to have the left hand side be a bool.
> 
> > It can be fixed by using ((display->flags & ALLEGRO_FULLSCREEN_WINDOW)
> > != 0), awesome -_-
> 
> Looks correct to me (unlike the above code).

You can write
    (onoff == !!(display->flags & ALLEGRO_FULLSCREEN_WINDOW))

> > I think we are also leaking out our definition of bool, so it's also
> > user's problem. Can we just define it to unsigned int?
> 
> We use the normal C99 type where we can, whatever we use on MSVC
> probably needs to conform to that or we end up with an incompatible
> library for MSVC compared with MinGW. So my gut reaction is to say
> "no".

To avoid confusion, we should have
    sizeof(C++ bool) == sizeof(C99 bool) == sizeof(Allegro bool) 

Peter




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/