assert(0)

Fyodor Ustinov via Digitalmars-d digitalmars-d at puremagic.com
Sat Nov 7 13:00:55 PST 2015


On Saturday, 7 November 2015 at 20:49:49 UTC, anonymous wrote:
> On 07.11.2015 21:38, Fyodor Ustinov wrote:
>> 1. I should generally _not_, but I _can_.
>
> D lets you to shoot your own foot, yes. You're encouraged not 
> to do it, though.
It's my opinion - shoot to my foot or not and select preffered 
weapon for it. :)

>> 2. Without "-release" assert(0) launches scope(exit), 
>> scope(failure) and
>> "finally" blocks. I.e. we get a completely different behavior 
>> in
>> "-release" and not "-release" mode.
>
> Yeah, -release drastically changes how asserts behave. That's 
> its purpose. A program should not fail asserts. If it does, 
> that's a bug. In particular, assert(0) should never be reached. 
> If it is reached, that's a bug.

We do not have way to in "scope(failure)" or "scope(exit)" detect 
- it's "assert" or "throw".

P.S.
I do not argue, "assert" - it's catch for fundamental programmers 
bug.



More information about the Digitalmars-d mailing list