[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..."
From: |
Paul Eggert |
Subject: |
Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..." |
Date: |
Sat, 30 Dec 2006 23:30:07 -0800 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux) |
Joe Buck <address@hidden> writes:
>> > *hv = (HOST_WIDE_INT) -(unsigned HOST_WIDE_INT) h1;
>>
>> Can't that conversion overflow?
>
> Not on a two's complement machine,
Sure it can. Suppose we have a 64-bit two's complement
machine with no padding, and h1 is - 2**63. Then (unsigned
HOST_WIDE_INT) h1 is 2**63, -(unsigned HOST_WIDE_INT) h1 is
also 2**63, and converting 2**63 to HOST_WIDE_INT overflows.
In this case C99 says the overflow results in an
implementation-defined value, or an implementation-defined
signal. If the former, the most plausible value is - 2**63
but C99 allows other values. If the latter, GCC will crash.
Either way, the code is "broken" -- unless you assume wrapv
semantics of course.
Even an expert like you can easily get this wrong, and this
suggests how tricky this area of Standard C really is. Only
a tiny fraction of C programmers know how to write this sort
of code reliably and in conformance to minimal standard C.
It's little wonder that most C programmers assume wrapv
semantics in cases like this.
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", (continued)
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Kenner, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Ian Lance Taylor, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Kenner, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Daniel Berlin, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Bruce Korb, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Bernd Schmidt, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Gabriel Dos Reis, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Joe Buck, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Kenner, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Joe Buck, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...",
Paul Eggert <=
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Kenner, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Vincent Lefevre, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Eric Blake, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Kenner, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Gabriel Dos Reis, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Guenther, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Gabriel Dos Reis, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Guenther, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Gabriel Dos Reis, 2006/12/30
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Robert Dewar, 2006/12/30