@safe pointer value modification
Neia Neutuladh
neia at ikeran.org
Sat Sep 8 17:06:20 UTC 2018
On Saturday, 8 September 2018 at 17:01:33 UTC, Jacob Shtokolov
wrote:
> So, modification of pointer values is prohibited (if I
> understand this sentence correctly).
@safe code can't manipulate the pointer itself, in order to avoid
memory corruption.
So this is forbidden:
void main() @safe
{
int* p = malloc(512);
p++;
}
But in @safe code, the compiler assumes that all pointers you
receive are valid. And the null pointer is also valid --
dereferencing it results in a segmentation fault rather than
memory corruption.
More information about the Digitalmars-d
mailing list