Jump to content

Create an object at a given address: Difference between revisions

m
no edit summary
(Added Kotlin)
mNo edit summary
Line 411:
s: [65 32 115 116 114 105 110 103 46 0]
a: [65 32 115 116 114 105 110 103 46 0]
</pre>
 
=={{header|Julia}}==
Julia has pointer access functions for interface with C code. Because the
address of a Julia integer variable within the VM may change when it is
re-assigned a new value, an array of a single integer is used below.
<lang julia>
function unsafepointers()
intspace = [42]
address = pointer_from_objref(intspace)
println("The address of intspace is $address")
anotherint = unsafe_pointer_to_objref(address)
println("intspace is $(intspace[1]), memory at $address, reference value $(anotherint[1])")
intspace[1] = 123456
println("Now, intspace is $(intspace[1]), memory at $address, reference value $(anotherint[1])")
end
 
unsafepointers()
</lang>
{{output}}<pre>
The address of intspace is Ptr{Void} @0x000000000729f130
intspace is 42, memory at Ptr{Void} @0x000000000729f130, reference value 42
Now, intspace is 123456, memory at Ptr{Void} @0x000000000729f130, reference value 123456
</pre>
 
4,105

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.