Re: [AD] bool in MSVC

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


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

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

And as I said, when you're testing bit flags, you should not be doing a direct comparison with a bool anyway (unless you're comparing against "false" maybe).

Evert





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