Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++.dos.16-bits - bool behaviour
Content-Type: text/plain; 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.28n 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.28n Jul 01 2002
|