Auxiliary copy object does not fill too bad though:
type
Kinds = enum
kA, kB, kC
ExampleBlock = object
case kind: Kinds
of kA: a: int
of kB: b: string
of kC: c: uint16
otherFields: array[16, int]
when isMainModule:
echo "Sizeof block, ", sizeof(ExampleBlock) # Is a union after all
let kindcrash = cast[ptr ExampleBlock](
alloc0(sizeof(ExampleBlock))
)
var copyObj = ExampleBlock(kind:kb)
copyObj.b = "String Test"
kindcrash[] = copyObj
echo kindcrash.kind
echo kindcrash.b
Run
- assign an object variant kind for unsafe memory block mrgaturus
- Re: assign an object variant kind for unsafe memory block treeform
- Re: assign an object variant kind for unsafe memory blo... treeform
