C `restrict` keyword in D
ag0aep6g via Digitalmars-d
digitalmars-d at puremagic.com
Mon Sep 4 02:15:30 PDT 2017
On 09/04/2017 06:10 AM, Moritz Maxeiner wrote:
> Indeed, but it also means that - other than null dereferencing - pointer
> issues can by made into reference issues my dereferencing a pointer and
> passing that into a function that takes that parameter by reference.
Why "other than null dereferencing"? You can dereference a null pointer
and pass it in a ref parameter. That doesn't crash at the call site, but
only when the callee accesses the parameter:
----
int f(ref int x, bool b) { return b ? x : 0; }
void main()
{
int* p = null;
/* Syntactically a null dereference, but doesn't crash: */
f(*p, false);
/* This crashes: */
f(*p, true);
}
----
More information about the Digitalmars-d
mailing list