Efficient detection of signed overflow?

me22 me22.ca@gmail.com
Sun Nov 29 21:01:00 GMT 2009


2009/11/29 Mark Dickinson <dickinsm@gmail.com>:
>
> This code is wrong, I think, because it depends on undefined
> behaviour.  I'm wondering how best to rewrite it so that (a)
> the replacement code is correct and portable C89, and (b)
> there's a reasonable chance of gcc compiling it to efficient
> assembler on common platforms.
>

What about using (long)((unsigned long)a + (unsigned long)b) or
something to get around the UB?



More information about the Gcc-help mailing list