I am importing an opaque struct from a C header, and think that the IncompleteStruct should be added. However, the documentation in the manual is confusing. Does it mean Nim won't use the sizeof of the native C struct or that it will?
The incompleteStruct pragma tells the compiler to not use the underlying C struct in a sizeof expression:
type
DIR* {.importc: "DIR", header: "<dirent.h>", pure, incompleteStruct.} = object
docs for incompleteStruct in manual should be improved.
see https://github.com/nim-lang/Nim/pull/14228
the meaning of {.incompleteStruct.} is for types like DIR (eg http://manpages.ubuntu.com/manpages/bionic/man7/dirent.h.7posix.html) which are forward declared, and hence for which sizeof (or accessing members or creating an instance on the stack etc) would result in cgen CT error on some platforms. Treating it like we used to (via void*) is clearly wrong though. Investigating how to best handle this...
there's also {.completeStruct.}, but it's unrelated to {.incompleteStruct.} (completeStruct is described in manual, hopefully in more details than incompleteStruct)
Oh wow! {.completeStruct.} is quite useful for me, I had no idea we had that!
I've wanted for a while to be able to make static assertions about the number of bytes taken up by arrays/objects containing types imported from C.
I gave it a try and it works a treat, but I can't see it in the manual. Does it still need documenting?