Re: Efficient detection of signed overflow?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/11/30 Florian Weimer <fw@xxxxxxxxxxxxx>:
>
>> On Sun, Nov 29, 2009 at 9:00 PM, me22 <me22.ca@xxxxxxxxx> wrote:
>>> What about using (long)((unsigned long)a + (unsigned long)b) or
>>> something to get around the UB?
>
> You'd also have to compare against (1 << (sizeof(long) * CHAR_BITS -
> 1)) instead of 0, pessimizing the code somewhat.
>

Why?  If numbers are 2s-complement, the cast back to a signed type is
well-defined, isn't it?

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux