Author: Sune Fischer
Date: 06:59:37 02/08/04
Go up one level in this thread
>
>Under MSVC, test the following:
>
> unsigned __int64 a = (1 << 50);
> printf("%I64u\n", a);
>
>What will the result be?... 0 ! No errors, no warnings.
I think the compiler sees the code as:
int one = 1;
__int64 a = one<<50;
so the behavior is expected, no warning should be given IMO, there are plenty of
cases where you deliberately want to over shift something to produce a zero.
>After debugging for several hours I finally found the problem and fixed it
>using:
>
> unsigned __int64 a = (1ui64 << 50);
>
>Yes, 1 should be written as 1ui64, or another solution:
>
> unsigned __int64 a = (((unsigned __int64) 1) << 50);
>
>Casting 1 to 64 bit.
You must do the cast before the operation, ie. if you do something like:
int x=...,y=...;
__int64 f = x*y;
it will not produce a __int64 result, similarly for a shift operation.
I'm pretty sure this is all standard C behavior.
>This is just a stupidity of MSVC. I was told that the Intel compiler gives an
>appropriate warning for the statement (1 << 50), and handles it correctly as 64
>bit.
I can't imagine it would do that, I don't think it would be correct according to
the standard.
-S.
This page took 0.01 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.