Julia: Is there a way to convert a number into a pointer?

As the title says, is there a way to convert a number (say a float or interger) that stores an address into a pointer?

For example, in Julia one can convert a pointer into a integer by doing:

data = [1, 2] 
ptr = pointer( data )      # Has type "Ptr{Int64}"
address = UInt64( ptr )    # Has type "UInt64"

How can one reverse these steps to get back the pointer? Say:

ptr = unknownFunction(address) # Has type "Ptr{Int64}"

Alternatively, is there a way to directly change the address held by a pointer? Say one has a pointer with:

Ptr{Int64} @0x0000000036f94110

How can you modify the address it hold to another number, for example 0x000000003ffffff0.

Read more here: https://stackoverflow.com/questions/67928344/julia-is-there-a-way-to-convert-a-number-into-a-pointer

Content Attribution

This content was originally published by snake_man_jim at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: