When you cast[UncheckedArray[uint8]], the compiler doesn't report an error, it just crashes.
var
rawMem = alloc0(20)
byteUA = cast[UncheckedArray[uint8]](rawMem)
byteUA[3] = 12'u8
echo byteUA[4]
Error: internal error: genAssignment: tyUncheckedArray
No stack traceback available
To create a stacktrace, rerun compilation with ./koch temp c <file>
The compiler should report that you need to cast to a ptr UncheckedArray[uint8], not UncheckedArray[uint8]
$ nim -v
Nim Compiler Version 0.19.9 [Linux: amd64]
Compiled at 2019-05-02
Copyright (c) 2006-2019 by Andreas Rumpf
active boot switches: -d:release
related issue: #9403
Casting unchecked array has worked for me (example). I'll try out your example tomorrow to understand what's different between the 2 cases. I am just allocating the exact array size using sizeof, whereas you are allocating using an int literal.
Crash aside, this is the correct solution:
var
rawMem = alloc0(20)
byteUA = cast[ptr UncheckedArray[uint8]](rawMem)
byteUA[3] = 12'u8
echo byteUA[4]
Arrays are not pointers in Nim. Never.
Ah yes, I missed that I am using cast[ptr .. in my example :)
Most helpful comment
Crash aside, this is the correct solution:
Arrays are not pointers in Nim. Never.