Skip to content

Instantly share code, notes, and snippets.

@ear7h
Created September 13, 2018 00:18
Show Gist options
  • Save ear7h/454223c3b63a80ed0802b6d778060993 to your computer and use it in GitHub Desktop.
Save ear7h/454223c3b63a80ed0802b6d778060993 to your computer and use it in GitHub Desktop.
reading in a struct (with only static sized types) in Nim
type
SomeStruct = object
longPtr: uint64
length: uint32
var x: ptr SomeStruct
var dat: array[12, char]
for ch in mitems(dat):
ch = high(char)
x = cast[ptr SomeStruct](addr(dat))
echo $x.length
echo $high(uint32) # confirm correctness
x.length = 0
echo $dat # check if it works the other way
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment