Why does this simple program segfault?

Chad J gamerChad at _spamIsBad_gmail.com
Wed Aug 15 16:27:51 PDT 2007


Jarrett Billingsley wrote:
> "Chad J" <gamerChad at _spamIsBad_gmail.com> wrote in message 
> news:f9tu35$1d7q$1 at digitalmars.com...
>> I think a worse problem though is how D errors on null dereferencing. On 
>> windows I get Access Violations, and I think the segv is a linux thing if 
>> I remember correctly.  Such error messages are completely unhelpful while 
>> debugging.  The following should probably be done:
>>
>> instance.member = something;
>>
>> becomes
>>
>> assert(instance !is null,
>>   format("%s,%d: %s is null!",
>>   __FILE__,__LINE__,instance.stringof)
>>   );
>> instance.member = something;
>>
>> It would be sort of like how arrays are bounds checked at runtime unless 
>> in release mode.
> 
> Was suggested, shot down, forgotten.  :\ 
> 
> 

grrrr.

This seems like low-lying fruit to me.

Considering the impressive stuff dmd does, I figured this would take 
very little effort to accomplish.  At the same time, this fix would save 
many programmers many hours of time, same as bounds checks.  This stuff 
has worked me over more than enough times.  The ubiquitous crappy 
runtime error messages need to go.


More information about the Digitalmars-d-learn mailing list