Author: Dieter Buerssner
Date: 09:05:12 02/08/04
Go up one level in this thread
On February 08, 2004 at 09:59:37, Sune Fischer wrote:
>>
>>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.
You cannot do this in Standard C.
6.5.7 Bitwise shift operators
[...] 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.
A warning would be useful anyway for a constant expression. Gcc: left shift
count >= width of type.
>>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.
First of all, when you are using __int64, you have left Standard C. Second, a
Standard compiler can give as many warnings as it likes. There are some compiler
diagnostics, that are required for a Standard conforming compiler, but non are
disallowed.
MSVC gives warnings for overflow of constant expressions (but not in this case).
It gives many warnings, I find annoying (for example a warning for "while(1){/*
With or without break inside */}"). A warning for 1<<52 would be more useful,
IMHO.
Regards,
Dieter
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.