This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Re: c/7284: incorrectly simplifies leftshift followed by signed power-of-2 division


> On 12/07/2002 15:12:01 nathan wrote:
> >Synopsis: incorrectly simplifies leftshift followed by signed power-of-2 
> >division
> >
> >State-Changed-From-To: open->closed
> >State-Changed-By: nathan
> >State-Changed-When: Fri Jul 12 07:12:01 2002
> >State-Changed-Why:
> >not a bug. for signed types, if 'n << c' overflows, the
> >behaviour is undefined.
> 
> There is no "overflow" in my sample code.  The operation of shifting 128 24 bits to the left on a
> 32-bit machine produces the bit pattern 0x80000000.
> No bits overflow.
> 
> The fact that a positive number may become negative when
> left-shifted is a property of the twos complement representation.
> The standard does not define signed left shift in terms of
> multiplication and certainly doesn't say that it is undefined when
> the apparently equivalent multiplication would be undefined.

>Before refering to the standard, you should probably >read it.

I read the C89 standard (and the C++ standard).  
You are referring to C99.  gcc was not defining __STDC_VERSION__, so C89, not C99, is surely the relevant standard.  The behaviour happens even if I explicitly set -std=c89, or if I use g++ 3.1, and you cannot justify either of those by reference to C99.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]