checkedint call removal

Ary Borenszweig via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 30 08:12:57 PDT 2014


On 7/30/14, 11:44 AM, Daniel Murphy wrote:
> "Ary Borenszweig"  wrote in message news:lravtd$2siq$1 at digitalmars.com...
>
>> Now, if you compile in release mode, according to Walter, all the
>> "asserts" are gone (which, as a side note, is something I don't like:
>> in every case it should throw an AssertError). So the question is: can
>> the compiler still replace that writeln call? It should, but since
>> there's nothing there preventing x + y to be different than 3 (the
>> assertion is gone), the compiler can't replace it anymore.
>
> That's the whole point - the compiler theoretically can optimize as if
> the assert is checked.
>
> (This example uses assert(0) because this behaviour is actually in the
> spec)
>
> if (x != 3) assert(0);
> if (x == 3) deleteAllMyFiles();
>
> The compiler is allowed to treat assert(0) as unreachable - and if it's
> unreachable then it must be impossible for x to be != 3.
>
> So it becomes:
>
> deleteAllMyFiles();
>
> He's asking for assert to mean 'check this condition' and assume to mean
> 'optimize as if this is a mathematical identity'.

And how is that different if instead of:

if (x != 3) assert(0);

you write:

assume(x != 3);

?


More information about the Digitalmars-d mailing list