C `restrict` keyword in D

ag0aep6g via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 4 03:24:48 PDT 2017

On 09/04/2017 11:47 AM, Moritz Maxeiner wrote:
> Still, though, this is surprising to me, because this means taking the 
> address of a parameter passed by reference (which is in your case is 
> typed as an existing int) can be null. Is this documented somewhere 
> (couldn't find it in the spec and it seems like a bug to me)?

I'm only aware of this part of the spec, which doesn't say much about 
ref parameters:


g++ accepts the equivalent C++ code and shows the same behavior. But, as 
far as I can tell, it's undefined behavior there, because dereferencing 
null has undefined behavior.

In D, dereferencing a null pointer is expected to crash the program. 
It's allowed in @safe code with that expectation. So it seems to have 
defined behavior that way.

But if a dereferencing null must crash the program, shouldn't my code 
crash at the call site? Or is there an exception for ref parameters? Any 
way, the spec seems to be missing some paragraphs that clear all this up.

More information about the Digitalmars-d mailing list