I am trying to figure out how to pass a reference ...
# kotlin-native
n
I am trying to figure out how to pass a reference to an int using kotlin native. I have sample C code
Copy code
#include<stdio.h>
#include<CL/cl.h>

int main(void)
{
    cl_int err;
    cl_uint numPlatforms;

    err = clGetPlatformIDs(0, NULL, &numPlatforms);
    if (CL_SUCCESS == err)
        printf("\nDetected OpenCL platforms: %d", numPlatforms);
    else
        printf("\nError calling clGetPlatformIDs. Error code: %d", err);

    return 0;
}
Here is what I thought the kotlin equivalent will be:
Copy code
fun main() {
    val numOfPlatforms: cl_uint = 0U
    val result = clGetPlatformIDs(0, null, cValuesOf(numOfPlatforms))
    if (CL_SUCCESS == result) {
        println("Detected OpenCL platforms: ${numOfPlatforms}")
    } else {
        println("Error calling clGetPlatformIDs. Error code: $result");
    }
}
However it seems that I am not passing the pointer to numOfPlatforms correctly as my program returns 0 instead of the expected value of 2. How do I pass a pointer to a an int using Kotlin native?
l
memScoped { val numOfPlatforms = alloc<UIntVar>() val result = clGetPlatformIDs(0, null, numOfPlatforms.ptr) }
👍 2