SHORT Re: Suggestion: "fix" assert(obj)

Bill Baxter dnewsgroup at billbaxter.com
Fri Jun 15 14:48:08 PDT 2007


Georg Wrede wrote:
> Walter Bright wrote:
>> Kristian Kilpi wrote:
>>
>>> The problem is that
>>>
>>>   assert(obj);
>>>
>>> does not first check if 'obj' is null.
>>
>>
>> Yes it does, it's just that the hardware does the check, and gives you 
>> a  seg fault exception if it is null.
> 
> Asserts were INVENTED to *avoid segfaults*.

What I find odd is that Walter often argues that things in D that *look* 
like C++ should *act* like C++ as much as possible.  As a C++ user I 
continually find it bizarre and hard to remember that assert() has these 
special cases.  There's also something unusual about assert(0), too.  It 
stays enabled in release mode.  And it's not a seg fault.  But assert on 
a 0 that happens to have a certain type is.  Odd.  Not making my life 
any easier I don't think.  I'm sure if I keep poking my brain and 
telling it "assert(object) is different!", I'll get it internalized 
eventually, but I really just don't find the "feature" of running 
invariants all that compelling.

--bb



More information about the Digitalmars-d mailing list