How should I be passing in a float pointer to a C ...
# kotlin-native
a
How should I be passing in a float pointer to a C function? Here’s the C code I’m trying to translate:
Copy code
void SetValue(const void *value, int type);

void main() {
    float runTime = 0.0f;

    while (true) {
        runTime++
        SetValue(&runTime, SET_VALUE_TYPE_RUNTIME);
        
        float target[3] = { 1.0f, 2.0f, 3.0f };
        SetValue(target, SET_VALUE_TYPE_TARGET);
    }
}
It makes sense to use
cValuesOf(1f, 2f, 3f)
for the target, since
target
is an array. But should I use
cValuesOf(runtime)
for a single number?
j
Does this work?
Copy code
fun main() {
    memScoped {
        val runTime = alloc<FloatVar>()
        while (true) {
            runTime.value++
            SetValue(runTime.ptr, SET_VALUE_TYPE_RUNTIME)

            val target = allocArrayOf(1f, 2f, 3f)
            SetValue(target, SET_VALUE_TYPE_TARGET)
        }
    }
}
I think
cValuesOf()
is immutable.