Signed integer overflow undefined behavior or not?

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 13 00:51:27 PST 2015


On 11/13/2015 12:30 AM, Ola Fosheim Grøstad wrote:
 > On Friday, 13 November 2015 at 06:46:37 UTC, Ali Çehreli wrote:
 >> Since it's UB in C and C++, I've heard that both clang and gcc do
 >> remove code branches if they can prove that there will be signed
 >> overflow. I don't know how or whether that optimization is turned off
 >> for D.
 >
 > The question you want to ask is probably if modular arithmetics is legal
 > D code for all integers, signed and unsigned. Can the programmer assume
 > that wrapping is legal D code?

I understood Walter's response to be so.

 > If so, then D does not have any kind of integer overflow at all, by
 > definition.

On the other hand, in order to define the wrapping behavior at all, one 
must speak of overflow first. Wrapping is the solution for the condition 
of overflow, which D must have to begin with, no? :)

Ali



More information about the Digitalmars-d mailing list