On Sunday, 15 November 2015 at 11:12:02 UTC, Tobias Pankrath
wrote:
On Sunday, 15 November 2015 at 10:59:43 UTC, Tobias Pankrath
wrote:
Point* p = (allocate memory from somewhere);
emplace!Point(p, 1, 2);
immutable(Point)* immutableP = cast(immutable(Point)*) p;
You could also use the emplac
On Sunday, 15 November 2015 at 10:59:43 UTC, Tobias Pankrath
wrote:
Point* p = (allocate memory from somewhere);
emplace!Point(p, 1, 2);
immutable(Point)* immutableP = cast(immutable(Point)*) p;
You could also use the emplace version that takes untyped memory:
http://dlang.org/phobos/std_con
this compiles and runs fine. Because emplace expects a typed
pointer, it actually modifies (*p).x and (*p).y
As far as I understand, this causes undefined behavior.
Are there any (safe) alternatives to this code other than
making the immutable members mutable?
As long as there are no other
According to http://dlang.org/const3.html any modification of
immutable data causes undefined behaviour. Now I want to
initialise a struct with immutable members in some malloc'd
memory and found the emplace function. I came up with the
following code:
import core.stdc.stdlib;
import std.con