Thread overview | |||||
---|---|---|---|---|---|
|
June 24, 2002 bool behaviour | ||||
---|---|---|---|---|
| ||||
Attachments:
| The following code snippet illustrates what I intended to do: bool bPatterns[sizeof(short)*8]; void getMaskpattern(unsigned short mask){ unsigned short i; for (i=0; i<sizeof(short) * 8; i++) bPatterns[i] = mask & (1 << i);} Took me a while to realise that the bool behavious is as if #define bool char And therefore the higher bits of mask is not "boolean copied" to the array. The compiler did not warn me about it for "type conversions". The fix is of course changing the assignment to bPatterns[i] = (mask & (1 << i)) != 0; Question:- What should be the correct behaviour for bool in the example above? DMC++ version 8.28n |
June 24, 2002 Re: bool behaviour | ||||
---|---|---|---|---|
| ||||
Posted in reply to KarL | KarL schrieb...
>
> The fix is of course changing the assignment to
> bPatterns[i] = (mask & (1 << i)) != 0;
> Question:-
> What should be the correct behaviour for bool in the example above?
>
> DMC++ version 8.28n
The standard says that there should be a boolean conversion. Therefore the explicit != 0 should not be neccessary. Seems like a bug in DMC.
Regards,
Heinz
|
July 01, 2002 Re: bool behaviour | ||||
---|---|---|---|---|
| ||||
Posted in reply to Heinz Saathoff | Thanks. I'll check it out. -Walter "Heinz Saathoff" <hsaat@bre.ipnet.de> wrote in message news:MPG.1780f0b4d4554bcc9896a8@news.digitalmars.com... > KarL schrieb... > > > > The fix is of course changing the assignment to > > bPatterns[i] = (mask & (1 << i)) != 0; > > Question:- > > What should be the correct behaviour for bool in the example above? > > > > DMC++ version 8.28n > > The standard says that there should be a boolean conversion. Therefore the explicit != 0 should not be neccessary. Seems like a bug in DMC. > > Regards, > Heinz |
Copyright © 1999-2021 by the D Language Foundation