Considering this code:
type
FooKind = enum
Alpha
Bravo
Charlie
Delta
Echo
Bar {.packed.} = object
typ {.bitsize: 2.}: FooKind
val {.bitsize: 6.}: int
Baz {.packed.} = object
val {.bitsize: 6.}: int
typ {.bitsize: 2.}: FooKind
var r = Bar(typ: Echo, val: 42)
var z = Baz(typ: Echo, val: 42)
echo "r: ", r
echo "z: ", z
The output is:
r: (typ: Alpha, val: -22)
z: (val: -22, typ: Alpha)
Of course one cannot encode 5 enum elements with only 2-bits. I understand that when I use pragmas, I'm overruling the compiler and am responsible for the results. But there are two things here that I didn't expect:
Is this is the expected behavior?