@@ -6412,26 +6412,27 @@ CompleteStruct pragma
6412
6412
-----------------------
6413
6413
By default, `importc ` types are considered incomplete: they may be lacking fields
6414
6414
in their nim declaration because these are unused in nim code or because of ABI
6415
- differences across platforms, in particular for padding fields. Field reordering
6415
+ differences across platforms, in particular for padding fields. Field reorderings
6416
6416
are also allowed. This prevents using `sizeof `, `alignof `, `offsetOf ` at compile
6417
6417
time.
6418
- These can still be used at runtime, deferring to calling `` sizeof ` ` (+ friends) in the
6418
+ These can still be used at runtime, deferring to calling `sizeof ` (+ friends) in the
6419
6419
backend generated code. In this case, they're known at backend compile time,
6420
6420
but not during nim semantic phase.
6421
6421
6422
- This ``completeStruct `` pragma overrides this behavior by telling the compiler
6423
- the type declaration in nim is fully specified, so that `sizeof `, `alignof `, `offsetOf `
6424
- are available at compile time. As a sanity check, `-d:checkAbi ` will insert
6425
- cgen static checks to make sure at least sizeof is correct.
6422
+ This `completeStruct ` pragma overrides this behavior by telling the compiler
6423
+ the type declaration in nim is fully specified and in correct order so that
6424
+ `sizeof `, `alignof `, `offsetOf ` are available at compile time.
6425
+ As a sanity check, `-d:checkAbi ` will insert backend static checks to make sure
6426
+ at least `sizeof ` is correct.
6426
6427
6427
6428
.. code-block :: Nim
6428
6429
type
6429
- TFoo* {.importc: "Foo", header: "<bar.h>",
6430
- pure, completeStruct.} = object
6431
- x*: cint # only 1 field in C declaration
6430
+ TFoo* {.importc: "struct Foo", header: "<bar.h>", completeStruct.} = object
6431
+ s1*: cint
6432
+ x2* {.importc: "_x2"}: pointer # renamed field
6432
6433
6433
- See `tests <https://github.com/nim-lang/Nim/blob/devel/tests/misc/msizeof5.nim >`_
6434
- The `` incompleteStruct ` ` pragma is now deprecated as it was implying the wrong
6434
+ See `additional examples <https://github.com/nim-lang/Nim/blob/devel/tests/misc/msizeof5.nim >`_.
6435
+ The `incompleteStruct ` pragma is now deprecated as it was implying the wrong
6435
6436
default.
6436
6437
6437
6438
Compile pragma
0 commit comments