You're right, it doesn't, once those assignments are wrapped in a main() You're gonna like this one even less but here you go: .emit:""" typedef struct Foo{ const int a; int b; }Foo; typedef struct Foo2{ int a; int b; }Foo2; """.} type constint {.importc: "const int".} = int Foo {.importc:"Foo".}= object a: constint b:int Foo2 {.importc:"Foo2".}= object a: int b: int proc makeit(c:var Foo,a,b:int)= var x = Foo2(a:a,b:b) copyMem(c.unsafeAddr,x.unsafeAddr,sizeof(Foo)) proc main()= var bar:Foo makeit(bar,5,7) echo bar.a,',',bar.b var baz:Foo #baz = bar #c error: assignment of readonly variable copyMem(baz.unsafeaddr,bar.unsafeaddr,sizeof(Foo)) echo baz.a,',',baz.b baz.b=9 echo baz.a,',',baz.b #baz.a=11#error assignment read-only member a main() Run
Foo2 has to be declared in the C source cuz otherwise the fields won't be in the right places.