[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GCC optimizes integer overflow: bug or feature?
From: |
Joe Buck |
Subject: |
Re: GCC optimizes integer overflow: bug or feature? |
Date: |
Tue, 19 Dec 2006 13:54:43 -0800 |
User-agent: |
Mutt/1.4.1i |
On Tue, Dec 19, 2006 at 10:25:41PM +0100, Denis Vlasenko wrote:
> ... It's not about standards. It's about sanity.
So what happens when two different people's concept of "sanity" differs?
That's why we have standards, so both can consult a reference and
wind up with the same concept, even though one of the two might not
like the answer.
The C language has several "insane" features. My least favorite
is this one:
int first_is_less(int i, unsigned u) {
return i < u;
}
...
int foo = first_is_less(-1, 1);
foo, of course, is "false": i is promoted to unsigned, yielding a
very large number, even though it would have been more logical for
comparisons to use the opposite promotion rule.
gcc produces a warning for these kinds of comparisons for that reason,
but that's all that it has freedom to do, since it is a C compiler,
not a "sanity" compiler.
C says that overflow with int is undefined. It also says that overflow
with unsigned is defined; unsigned types obey the rules of arithmetic
modulo 2**N. If that's what you want, C gives you a way to do it.
Resistance is futile, you will be p0wned if you don't properly understand
how integer overflow works in C (Google: CERT integer overflow). Sorry.
- Re: GCC optimizes integer overflow: bug or feature?, (continued)
- 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 <=
- Re: GCC optimizes integer overflow: bug or feature?, Andrew Haley, 2006/12/20
- 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