unsafe_convert
unsafe_convert(T,x)
Convert x
to a value of type T
In cases where convert
would need to take a Julia object and turn it into a Ptr
, this function should be used to define and perform that conversion.
Be careful to ensure that a julia reference to x
exists as long as the result of this function will be used. Accordingly, the argument x
to this function should never be an expression, only a variable name or field reference. For example, x=a.b.c
is acceptable, but x=[a,b,c]
is not.
The unsafe
prefix on this function indicates that using the result of this function after the x
argument to this function is no longer accessible to the program may cause undefined behavior, including program corruption or segfaults, at any later time.
Examples
unsafe_convert(T, x)
Convert x
to a value of type T
.
In cases where convert
would need to take a Julia object and turn it into a Ptr
, this function should be used to define and perform that conversion.
Be careful to ensure that a Julia reference to x
exists as long as the result of this function will be used. Accordingly, the argument x
to this function should never be an expression, only a variable name or field reference. For example, x = a.b.c
is acceptable, but x = [a, b, c]
is not.
The unsafe
prefix on this function indicates that using the result of this function after the x
argument to this function is no longer accessible to the program may cause undefined behavior, including program corruption or segfaults, at any later time.
Example usage:
julia> ptr = unsafe_convert(Ptr{Int}, 123)
Ptr{Int64} @0x0000000123456789
julia> unsafe_load(ptr)
123
In this example, unsafe_convert
is used to convert the integer 123
to a pointer of type Ptr{Int}
. The resulting pointer ptr
can then be used with unsafe_load
to retrieve the value.
See Also
base, big, bytes2hex, cconvert, complex, convert, dec, hex, hex2bytes, hex2num, oct, oftype, parse, promote, signed, unsafe_convert, unsigned, widen,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.