Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Microsoft follies (visual C/C++ 6.0) Answer found. (cough, cough) :)

Author: Uri Blass

Date: 10:06:00 02/08/04

Go up one level in this thread


On February 08, 2004 at 12:55:54, Sune Fischer wrote:

>On February 08, 2004 at 12:05:12, Dieter Buerssner wrote:
>
>>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.
>
>I knew about the negative shift but not the latter.
>I wonder why that is the case, I see no reason why it should be undefined.
>
>>A warning would be useful anyway for a constant expression. Gcc: left shift
>>count >= width of type.
>
>It's just a way of writing a constant, ie. would you also want a warning on 1<<2
>saying that constant 1 being altered to 4?
>
>The compilers intent would be to tell you that if you want 4 and not 1, why not
>just write 4 instead of 1?

This is different
Here 2^2=4 and 2^50!=0

Warning that 1<<50 is not 2^50 is a clearly useful warning.

Uri



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.