c++.dos.16-bits - bool behaviour
- KarL (16/16) Jun 24 2002 charset="iso-8859-1"
- Heinz Saathoff (5/12) Jun 24 2002 The standard says that there should be a boolean conversion. Therefore
- Walter (3/15) Jul 01 2002 Thanks. I'll check it out. -Walter
charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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=3D0; i<sizeof(short) * 8; i++) bPatterns[i] =3D 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] =3D (mask & (1 << i)) !=3D 0; Question:- What should be the correct behaviour for bool in the example above? DMC++ version 8.28n
Jun 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.28nThe 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
Jun 24 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.28nThe 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
Jul 01 2002