Skip to content

Conversation

@ringabout
Copy link
Member

@ringabout ringabout commented Oct 30, 2025

  type
    DIR* {.importc: "DIR", header: "<dirent.h>", incompleteStruct.} = object
    Dirent* {.importc: "struct dirent", header: "<dirent.h>".} = object
      d_type* {.importc: "d_type".}: uint8
      d_name* {.importc: "d_name".}: array[256, char]

As in Nim, DIR is marked incompleteStruct.

Since DIR is forward declared, we can not access its size. We need to handle the sizeof for it specifically

In Nim, it causes problems for genTypeInfo. And some (mis)usage still produce code gen errors

type
  DIR* {.importc: "DIR", header: "<dirent.h>", incompleteStruct.} = object

let sss = sizeof(DIR)
echo sss

or use DIR as fields of objects without reference, name using DIR by value

In Nimony, it seems that only sizeof concerns incompleteStruct for now, i.e., sizeof(DIR). Since any type using DIR by
value already produces code gen errors. This PR should make sizeof(DIR) use the size of a pointer, while incompleteStruct might be useful in the future

@Araq
Copy link
Member

Araq commented Oct 30, 2025

Well sizeof must detect this pragma and return "unknown" (I don't know if it can do that already, but we need this).

@ringabout ringabout marked this pull request as ready for review October 31, 2025 08:30
@ringabout
Copy link
Member Author

type
  DIR* {.importc: "DIR", header: "<dirent.h>", incompleteStruct.} = object

const s = sizeof(DIR)

With the compat mode, it gives cannot evaluate expression at compile time

@Araq Araq merged commit d41ffa3 into master Oct 31, 2025
3 checks passed
@Araq Araq deleted the pr_Laune branch October 31, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants