0

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] = // ?
Progman
  • 16,827
  • 6
  • 33
  • 48
R A
  • 149
  • 1
  • 9

1 Answers1

1

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)
R A
  • 149
  • 1
  • 9