Hi, I'm trying to interface some C library where the library function accepts a function pointer for callbacks.
proc libfun(fun:proc(x:pointer; n:ptr cint)) {.importc:"libfun", header:"mylib.h".}
I'm trying to write this fun proc in Nim, and pass it to libfun. How do I treat this x:pointer as an array? I want to do simple things as *(x+int_number) in C. I'm currently doing cast[ref array[0..0,float]](x), and removing bounds checking. But is there a better way to do this in Nim? I'm using
template asarray*[T](p:pointer):auto =
type A{.unchecked.} = array[0..0,T]
cast[ptr A](p)
for now.
Is there a difference between cast[ptr A](p) and cast[ref A](p) here?
.... an std::shared_ptr ... then ref A takes over the ownership
Is it the same when the backend is C?
Have compiler already warned if there's untracked reference cast to tracked reference?