You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
discard """
errormsg: "cannot evaluate 'sizeof/alignof' because its type is not defined completely"
line: 9
"""
type
MyStruct {.importc: "MyStruct".} = object
const i = sizeof(MyStruct)
echo i
instead of cannot evaluate 'sizeof/alignof' because its type is not defined completely for all importc types we can restrict this error to cases where type is marked with {.incomplete.}
Furthermore, we can add optional annotations {.sizeof: 32, alignof:32.} pragma for cases of {.incomplete.} types T so that T.sizeof can just use that directly, when available
The text was updated successfully, but these errors were encountered:
timotheecour
changed the title
incomplete importc types should be annotated with incomplete and optional sizeof pragmas
incomplete importc types should be annotated with incomplete and optional sizeof pragmas
Oct 8, 2018
There is a size pragma for imported types, though it is very restricted at the moment: #7674
timotheecour
changed the title
incomplete importc types should be annotated with incomplete and optional sizeof pragmas
incomplete importc types should be annotated with incomplete and optional sizeof / alignof pragmas
Oct 10, 2018
That is isteresting. But for a recursive calculation of object sizes it is important to know borth size and alignment. Just setting the size does not really help.
Alignment is often very platform, compiler and compiler flag dependent. you can't just measure alignment and size and set it as a constant. If something goes wrong here, debugging will be horrible.
/cc @krux02
this would help with #5664 (implement sizeof and alignof operator) for importc types:
cda1ab4#diff-3ff4bd5c972c5629ed4e7e62596e3b3bR326
# TODO there is no proper way to find out if a type cannot be queried for the size.
as well as here:
cda1ab4#diff-e3317694adf0c30fc5d1562cb85f4d40R2
instead of
cannot evaluate 'sizeof/alignof' because its type is not defined completely
for all importc types we can restrict this error to cases where type is marked with{.incomplete.}
Furthermore, we can add optional annotations
{.sizeof: 32, alignof:32.}
pragma for cases of{.incomplete.}
types T so thatT.sizeof
can just use that directly, when availableThe text was updated successfully, but these errors were encountered: