assume, assert, enforce, @safe

Daniel Gibson via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 1 13:30:19 PDT 2014


Am 01.08.2014 22:16, schrieb eles:
> On Friday, 1 August 2014 at 17:43:27 UTC, Timon Gehr wrote:
>> On 08/01/2014 07:19 PM, Sebastiaan Koppe wrote:
>
>> The debug and the release build may be subjected to different input
>> and hence traverse different traces of abstract states. It is not
>> valid to say that an assertion will never fail just because it hasn't
>> failed yet.
>
> Yes, but is the same for the C apps. There, you have no assertion in the
> release build, the release build is optimized (I imagine very few would
> use -O0 on it...), then the sefault happens.
>

But there checks are not optimized away because of assert.
assert(x != NULL);
if(x != NULL) { ... }
in C the if check won't be optimized away in NDEBUG builds, in 
equivalent D code it would, because the assert would make the compiler 
assume that x will never be NULL at that point.

Cheers,
Daniel


More information about the Digitalmars-d mailing list