|
From: Ioannis V. <no...@ho...> - 2003-03-05 09:39:44
|
-------Original Message-------=0D
=0D
From: Per Westermark=0D
Date: =D4=E5=F4=DC=F1=F4=E7, 5 =CC=DC=F1=F4=E9=EF=F2 2003 9:39:19 =F0=EC=0D
To: Ioannis Vranos=0D
Cc: Dev-C++ Mailing List=0D
Subject: Re: [Dev-C++] Character variables=0D
=0D
The next step of from the 32-bit case statement below would be to use a=0D
hash table.=0D
=0D
However, how would you replace the switch statement with std::bitset?=0D
=0D
=0D
=3D=3D> At first as i said applying the bitwise operators on a signed int=
eger is
bad magic. They are intended for unsigned integrals only. Violation of th=
is
can lead to overflows and open the door of our Universe to dragons, elves
and other bad-meaning creatures.=0D
=0D
=0D
How i would replace the switch statement with bitset:=0D
=0D
Let's assume we had:=0D
=0D
bitset<32>tag(0);=0D
=0D
// I assume you wanted this:=0D
bitset<4>buf('a'+'b');=0D
=0D
for (size_t i =3D 0; i < 4; i++)=0D
tag =3D (tag << 8) | buf[i++];=0D
=0D
=0D
switch (tag.to_ulong())=0D
{=0D
case 'STRT': ...; break;=0D
case 'HEDR': ...; break;=0D
case 'DATA': ...; break;=0D
case 'ENDF': ...; break;=0D
}=0D
=0D
=0D
Ioannis Vranos=0D
=0D
* Programming pages: http://www.noicys.freeurl.com=0D
* Alternative URL: http://run.to/noicys=20 |