Hi there, How do I properly use writeBuffer procedure? I can't find how to pass a pointer to the array which I guess is the problem... Thanks.
var f = open("mypath", fmWrite)
let aaa = [1,2,3]
writeBuffer(f, aaa ,cast[int](3))
var f = open("mypath", fmWrite)
var aaa = [1,2,3]
let written = f.writeBuffer(addr aaa, sizeof(aaa))
You need to use var instead of let so that aaa can even have an address. The address of a let would not always make sense, so it doesn't work. The size of the buffer is in bytes, so it has to be 3 * sizeof(int) or simply sizeof(aaa).
Thanks, that works. One thing which still confuses me is the following:
f.writeBuffer (addr aaa ,sizeof(aaa)) # Error: value of type 'int' has to be discarded
let written = f.writeBuffer (addr aaa ,sizeof(aaa)) # compiles fine
I don't get why I'm expected to store the result in the variable?