Why does this simple program segfault?

Robert Fraser fraserofthenight at gmail.com
Tue Aug 14 17:32:17 PDT 2007


Bill Baxter Wrote:

> Isn't there something we can do about this?  I do this about once a day 
> when in a heavy D using phase.  It bites newbies and not-so-newbies 
> alike.  I almost think it should be made so that no initializer calls 
> the default constructor, and if you really want it to be null then you 
> should initialize with null:
> 
>     Tester fun;  // creates a new Tester
>     Tester nofun = null;  // doesn't create anything

But then I (coming from a Java background) would be bitten by it about once a day.

I think the best way is to make a compiler warning for every local variable that's used before it's explicitly assigned, a la Java (actually, it's an error in Java).


More information about the Digitalmars-d-learn mailing list