nim-lang / c2nim

c2nim is a tool to translate Ansi C code to Nim. The output is human-readable Nim code that is meant to be tweaked by hand before and after the translation process.
MIT License
509 stars 63 forks source link

`importc` not generated for typedef #242

Open arnetheduck opened 2 years ago

arnetheduck commented 2 years ago
typedef void (*some_proc)(const void *key);

void xxx(some_proc p);
type
  SomeProc* = proc (key: pointer) {.cdecl.}

proc xxx*(p: SomeProc) {.cdecl, importc: "xxx", header: "test.h".}

importc here is needed to ensure that the C typedef is used where relevant, and not the thing that Nim thinks is equivalent: Nim lacks the language to represent const void* correctly - this leads to compile issues down the line with const-vs-non-const type problems.

The above should be SomeProc* {.importc: "some_proc", header: "test.h".} = proc (key: pointer) {.cdecl.}