type
jack_nframes_t* = uint32
jack_default_audio_sample_t* = cfloat
Sample* = jack_default_audio_sample_t
Samples*{.unchecked.} = array[0..0, Sample]
proc jack_port_get_buffer*(port: ptr jack_port_t; a3: jack_nframes_t): ptr Samples {.
importc: "jack_port_get_buffer", dynlib: "libjack.so.0.1.0".}
# C interface:
# void * jack_port_get_buffer (jack_port_t *port, jack_nframes_t) JACK_OPTIONAL_WEAK_EXPORT;
What I'm confused about is the need for the ptr in the return type. My intuition was that type Samples itself represented a pointer to the array.
Furthermore, when I was returning just type Samples and trying to populate the array (in a callback from a c function) my loop tended to terminate after 10 to 20 assignments. But I didn't crash or get a segfault. Wrapping the assignment in an exception handler didn't catch anything.
So when I was handing the return type as plain Samples and trying to populate it, what was actually happening? I'm willing imagine a universe where I was somehow expecting to return the array by value. But without a bound, what would that even mean?
My intuition was that type Samples itself represented a pointer to the array.
It is an array, not a pointer. See
https://en.wikipedia.org/wiki/Array#In_computer_science
Note that the * in Nim denotes export of that symbol, and does not indicate pointers as in C language.
I understand about the asterisk.
So leaving the ptr off the function and then calling it resulted in returning an unchecked array of zero length by value?
And since it was unchecked I was bashing the stack by trying to assign to it?
This is just what c2nim spit out except that I changed the return type to make it useful.
I'm sure you are right that this isn't idiomatic Nim. I'm too new to have any sense of that.