Files
kotlin-fork/backend.native/tests/interop/basics/3.kt
T
Svyatoslav Scherbina 50c3be3fc2 Simplify working with values in interop
* Access primitive interop array elements and struct fields without `.value`
* Simplify C*Var* interop types names
2017-03-31 11:44:07 +03:00

30 lines
669 B
Kotlin

import kotlinx.cinterop.*
fun main(args: Array<String>) {
memScoped {
val count = 5
val values = allocArray<IntVar>(count)
values[0] = 14
values[1] = 12
values[2] = 9
values[3] = 13
values[4] = 8
cstdlib.qsort(values, count.toLong(), IntVar.size, staticCFunction(::comparator))
for (i in 0 .. count - 1) {
print(values[i])
print(" ")
}
println()
}
}
private fun comparator(a: COpaquePointer?, b: COpaquePointer?): Int {
val aValue = a!!.reinterpret<IntVar>()[0]
val bValue = b!!.reinterpret<IntVar>()[0]
return (aValue - bValue)
}