Author: Dann Corbit
Date: 06:18:14 07/05/02
Go up one level in this thread
On July 04, 2002 at 10:46:52, Sune Fischer wrote:
[snip]
>>In VC++ you can write: (0xFFi64 << (r << 3))
>
>right, i64 works.
That's another bug. You should used unsigned instead of signed.
It's either 0xFFui64 or 0xFFi64u (I forget which) for MS VC++.
A hint from the C FAQ:
20.15b: People claim that optimizing compilers are good and that we no
longer have to write things in assembler for speed, but my
compiler can't even replace i/=2 with a shift.
A: Was i signed or unsigned? If it was signed, a shift is not
equivalent (hint: think about the result if i is negative and
odd), so the compiler was correct not to use it.
And from the ANSI C Standard:
3.4.1
1 implementation-defined behavior
unspecified behavior where each implementation documents how the choice is made
2 EXAMPLE An example of implementation-defined behavior is the propagation of
the high-order bit when a signed integer is shifted right.
6.5.7 Bitwise shift operators
Syntax
1 shift-expression:
additive-expression
shift-expression << additive-expression
shift-expression >> additive-expression
Constraints
2 Each of the operands shall have integer type.
Semantics
3 The integer promotions are performed on each of the operands. The type of the
result is that of the promoted left operand. If the value of the right operand
is negative or is greater than or equal to the width of the promoted left
operand, the behavior is undefined.
4 The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are
filled with zeros. If E1 has an unsigned type, the value of the result is E1 ´
2E2, reduced modulo one more than the maximum value representable in the result
type. If E1 has a signed type and nonnegative value, and E1 ´ 2E2 is
representable in the result type, then that is the resulting value; otherwise,
the behavior is undefined.
5 The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an
unsigned type or if E1 has a signed type and a nonnegative value, the value of
the result is the integral part of the quotient of E1 / 2E2. If E1 has a signed
type and a negative value, the resulting value is implementation-defined.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.