GCC Undefined Behavior Sanitizer
via Digitalmars-d
digitalmars-d at puremagic.com
Mon Oct 20 00:13:07 PDT 2014
On Monday, 20 October 2014 at 06:17:40 UTC, Walter Bright wrote:
> On 10/19/2014 1:56 AM, Iain Buclaw via Digitalmars-d wrote:
>> Good thing that overflow is strictly defined in D then. You
>> can rely on
>> overflowing to occur rather than be optimised away.
>
> Yeah, but one has to be careful when using a backend designed
> for C that it doesn't use the C semantics on that anyway.
8-I
And here I was hoping that Iain was being ironic!
If you want to support wrapping you could do it like this:
int x = @@wrapcalc( y + DELTA );
And clamping:
int x = @@clampcalc(y+ DELTA);
And overflow
int x = y+DELTA;
if(x.status!=0){
x.status.carry…
x.status.overflow…
}
or
if(@@overflowed( x=a+b+c+d )){
if(@@overflowed( x=cast(somebigint)a+b+c+d )){
throw …
}
}
or
int x = @@throw_on_overflow(a+b+c+d)
More information about the Digitalmars-d
mailing list