|
From: Ioannis V. <no...@ho...> - 2003-03-05 12:22:08
|
-------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 2:04:36 =EC=EC=0D To: Ioannis Vranos=0D Cc: Dev-C++ Mailing List=0D Subject: Re: [Dev-C++] Character variables=0D =0D The shift operators are of course defiend for both signed and unsigned=0D data types.=0D =0D It's just that for >> you may not assume if it will shift in a '0' or a=0D '1' in the most significant bit fir signed integers, i.e.=0D =0D -3 (0xfffd) >> 1 =3D 32766 (0x7ffe)=0D -3 (0xfffd) >> 1 =3D -2 (0xfffe)=0D =0D depending on implementation.=0D =0D However, when shifting in characters into a 32-bit integer, I don't have=0D to care about this, since << always shifts in 0 in the least significant=0D bit.=0D =0D =0D =3D=3D> Yes bitwise operators can be applied to integral types signed and unsigned however in signed types the behaviour is implementation dependent/undefined. This is explicitly mentioned in the C99 standard:=0D =0D =3D=3D> "Some operators (the unary operator ~, and the binary operators <= <, >>, &, ^, and |,=0D collectively described as bitwise operators) are required to have operand= s that have=0D integer type. These operators return values that depend on the internal representations of=0D integers, and have implementation-defined and undefined aspects for signe= d types."=0D =0D =0D =3D=3D> The above is not mentioned explicitly in the C++98 standard, but = it is common sense. That's why i spoke about bad magic. :)=0D =0D =0D =0D Ioannis Vranos=0D =0D * Programming pages: http://www.noicys.freeurl.com=0D * Alternative URL: http://run.to/noicys=20 |