[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GCC optimizes integer overflow: bug or feature?
From: |
Andrew Haley |
Subject: |
Re: GCC optimizes integer overflow: bug or feature? |
Date: |
Wed, 20 Dec 2006 11:42:29 +0000 |
Denis Vlasenko writes:
> On Tuesday 19 December 2006 20:05, Andrew Haley wrote:
> > Denis Vlasenko writes:
> > >
> > > I wrote this just a few days ago:
> > >
> > > do {
> > > int32_t v1 = v << 1;
> > > if (v < 0) v1 ^= mask;
> > > v = v1;
> > > printf("%10u: %08x\n", c++, v);
> > > } while (v != 1);
> > >
> > > I would become rather sad if this will stop compiling correctly.
> >
> > I can understand the objections to do with "dusty deck" code that
> > hasn't been looked at for aeons, but in the case of code that you
> > wrote so recently, given that you understand the issue, why not simply
> > use the standard idiom?
>
> I want sane compiler.
> One in which N-bit integer variables stay exactly N-bit.
> Without "magic" N+1 bit which is there "somethimes". a*2/2:
> If I say "multiply by 2 and _after that_ divide by 2,
> I meant that. Compiler can optimize it any way it wants,
> as long as result is the same as unoptimized one.
This kind of thinking was appropriate before standardization.
But C changed. C is no longer a kind of high-level assembly laguage:
it's defined by a standard, in terms of an abstract machine, and some
operations are not well-defined. If you want your programs to do what
you expect, you'd better find out what that abstract machine does.
> Above: v is a signed entity. I expect (v < 0) to be equal to
> "most significant bit is set". It's not about standards.
> It's about sanity.
You'd better find some other programming langauge that is defined the
way you want.
Andrew.
- Re: GCC optimizes integer overflow: bug or feature?, (continued)
- Re: GCC optimizes integer overflow: bug or feature?, Paul Eggert, 2006/12/21
- Re: GCC optimizes integer overflow: bug or feature?, Ian Lance Taylor, 2006/12/21
- Re: GCC optimizes integer overflow: bug or feature?, Joseph S. Myers, 2006/12/21
- Re: GCC optimizes integer overflow: bug or feature?, Paul Eggert, 2006/12/21
- Re: GCC optimizes integer overflow: bug or feature?, Gabriel Dos Reis, 2006/12/21
- Re: GCC optimizes integer overflow: bug or feature?, Paolo Bonzini, 2006/12/22
- Re: GCC optimizes integer overflow: bug or feature?, Paolo Bonzini, 2006/12/22
- Re: GCC optimizes integer overflow: bug or feature?, Paul Eggert, 2006/12/29
- Message not available
- Re: GCC optimizes integer overflow: bug or feature?, Toon Moene, 2006/12/27
- Re: GCC optimizes integer overflow: bug or feature?, Joe Buck, 2006/12/20
- Re: GCC optimizes integer overflow: bug or feature?,
Andrew Haley <=
- Re: GCC optimizes integer overflow: bug or feature?, Gabriel Dos Reis, 2006/12/20
- RE: GCC optimizes integer overflow: bug or feature?, Dave Korn, 2006/12/20
- Re: GCC optimizes integer overflow: bug or feature?, Dorit Nuzman, 2006/12/20
- Re: GCC optimizes integer overflow: bug or feature?, Andrew Haley, 2006/12/19
- Re: GCC optimizes integer overflow: bug or feature?, Robert Dewar, 2006/12/19
- Re: GCC optimizes integer overflow: bug or feature?, Gabriel Dos Reis, 2006/12/19
- Re: GCC optimizes integer overflow: bug or feature?, Andrew Haley, 2006/12/19
- Re: GCC optimizes integer overflow: bug or feature?, Gabriel Dos Reis, 2006/12/19
- Re: GCC optimizes integer overflow: bug or feature?, Robert Dewar, 2006/12/19
- Re: GCC optimizes integer overflow: bug or feature?, Robert Dewar, 2006/12/19