Thread overview
bool behaviour
Jun 24, 2002
KarL
Jun 24, 2002
Heinz Saathoff
Jul 01, 2002
Walter
June 24, 2002
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
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
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