I am trying to read c-array into a sequence. If somebody could confirm if my
understanding is correct.
In one hand, I have in C world: an address, the array size and the type.
Something like: bufferptr, size and uint8 (it contains an image).
In order to load the buffer into the seq, is the following right?
var data = newSeq[uint8](size)
for i in 0..<size:
data[i] = cast[seq[uint8]](bufferptr)[i]
Run
Another thing that I would like to understand is pointer airithmetic. Is the
following right?
1. In order to operate with pointer, first cast the pointer to an int in
order of being able to operate with it. This is done with cast[int](bufferptr).
2. Once we have done pointer arithmetic, we cast it back to a pointer. That
would be address.
3. Finally, we get the content from that address casting it into a uint8.
That would be value.
let address = cast[pointer]( cast[int](bufferptr) + offset )
let value = cast[uint8](address)
Run
Is my understanding correct?