Can the compiler catch my stupid mistake?

Meta via Digitalmars-d digitalmars-d at
Fri Aug 14 11:02:08 PDT 2015

On Friday, 14 August 2015 at 17:59:12 UTC, Jack Stouffer wrote:
> On Friday, 14 August 2015 at 17:44:11 UTC, Steven Schveighoffer 
> wrote:
>> On 8/14/15 1:36 PM, Jack Stouffer wrote:
>>> Recently, I made the mistake of trying to reference an enum 
>>> pointer in a
>>> struct before it was set (see example below). I was wondering 
>>> if it's
>>> possible for DMD to catch this mistake at compile time, as 
>>> this
>>> currently compiles fine and segfaults on execution.
>> state *is* set to null, before your constructor is called. The 
>> access is not "before it was set".
>> Could the compiler *possibly* flag this as an error? It could, 
>> but it doesn't, and likely won't in the future.
>> -Steve
> I'm confused. If state is set to null on struct initialization, 
> then why does accessing that memory segfault? Shouldn't the if 
> condition just fail?

You're dereferencing a null pointer

More information about the Digitalmars-d mailing list