Create an object at a given address: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: update output)
(Added Nim example)
Line 505: Line 505:
</lang>
</lang>


=={{header|Nim}}==

<lang nim>type
MyObject = object
x: int
y: float

var
mem = alloc(sizeof(MyObject))
objPtr = cast[ptr MyObject](mem)
echo "object at ", cast[int](mem), ": ", objPtr[]

objPtr[] = MyObject(x: 42, y: 3.1415)
echo "object at ", cast[int](mem), ": ", objPtr[]
</lang>

Output:
<pre>
object at 139966605271112: (x: 0, y: 0.0)
object at 139966605271112: (x: 42, y: 3.1415)
</pre>


=={{header|Pascal}}==
=={{header|Pascal}}==