What's the right way to convert VM's Int
to unmanaged CInt
pointer from scala.scalanative.unsafe
?
val num: Int = 5
val nativeInt: Ptr[CInt] = // ?
This seems to be working for me:
def toCIntPtr(num: Int)(using z: Zone): Ptr[CInt] = {
val nativeInt: Ptr[CInt] = alloc[CInt](sizeof[CInt])
!nativeInt = num
nativeInt
}
// implicit zone present
val num: Int = 5
val nativeInt: Ptr[CInt] = toCIntPtr(num)