Simplify working with values in interop
* Access primitive interop array elements and struct fields without `.value` * Simplify C*Var* interop types names
This commit is contained in:
committed by
SvyatoslavScherbina
parent
f94a47518a
commit
50c3be3fc2
@@ -4,17 +4,17 @@ fun main(args: Array<String>) {
|
||||
memScoped {
|
||||
val count = 5
|
||||
|
||||
val values = allocArray<CInt32Var>(count)
|
||||
values[0].value = 14
|
||||
values[1].value = 12
|
||||
values[2].value = 9
|
||||
values[3].value = 13
|
||||
values[4].value = 8
|
||||
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(), CInt32Var.size, staticCFunction(::comparator))
|
||||
cstdlib.qsort(values, count.toLong(), IntVar.size, staticCFunction(::comparator))
|
||||
|
||||
for (i in 0 .. count - 1) {
|
||||
print(values[i].value)
|
||||
print(values[i])
|
||||
print(" ")
|
||||
}
|
||||
println()
|
||||
@@ -22,8 +22,8 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
|
||||
private fun comparator(a: COpaquePointer?, b: COpaquePointer?): Int {
|
||||
val aValue = a!!.reinterpret<CInt32Var>().pointed.value
|
||||
val bValue = b!!.reinterpret<CInt32Var>().pointed.value
|
||||
val aValue = a!!.reinterpret<IntVar>()[0]
|
||||
val bValue = b!!.reinterpret<IntVar>()[0]
|
||||
|
||||
return (aValue - bValue)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user