Struct with default ctor (Was: [dmd-beta] dmd 2.064 beta take 2)

Timon Gehr timon.gehr at gmx.ch
Sun May 19 12:54:36 PDT 2013


On 05/19/2013 09:42 PM, Walter Bright wrote:
> On 5/19/2013 12:31 PM, Minas Mina wrote:
>> On Sunday, 19 May 2013 at 18:30:09 UTC, deadalnix wrote:
>>> void buzz(Foo f) {
>>>     f.foo(); // Rely in faith. It is invalid and way easier to write
>>> than the
>>> valid code, which is THE recipe for it to spread.
>>> }
>>
>> Shouldn't this throw a NullPointerSomething?
>
> It throws a seg fault at runtime. It *is* checked for by the hardware.

Yes, but this code looks like it calls method 'foo', which is probably 
its intention. Hence it is buggy.

D's current answer is the following:

void buzz(Foo f)in{assert(!!f);}body{
     f.foo();
}



More information about the Digitalmars-d mailing list