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
508 stars 63 forks source link

invalid code generated for `extern const` #241

Open arnetheduck opened 2 years ago

arnetheduck commented 2 years ago

Header:

extern const int xxx_symbol;

Command:

$ c2nim --version
0.9.18

$ c2nim --header --importc --nep1 test.h

Output:

let xxxSymbol* {.header: "test.h".}: cint

several problems with the generated definition:

Of course, the main issue here is that Nim has no feature that expresses the concept of an extern const in general, so var is the closest that we can get.

Araq commented 2 years ago

let x {.importc.} <init missing> is Nim's notion of "extern const". IIRC this was added for this reason.

arnetheduck commented 2 years ago

is Nim's notion of "extern const"

right, I was testing this with nim 1.2 where it's not allowed - it's also still missing the actual importc