I need to wrap C constant which can be either #define or const int, it is in standard C header so in order to be portable I can't specify the value, run c2nim or assume something.

The following does work:

var FLT_MIN {. importc: "FLT_MIN" header: "<float.h>" .} : cfloat

But unfortunately, the FLT_MIN is declared as var causing a havoc in the side effect tracking we are using. The following does not seem to work:

const FLT_MIN {. importc: "FLT_MIN" header: "<float.h>" .} : cfloat

Any better ideas?


2018-04-16 13:40:53

const FLT_MIN = 1.175494350822288e-038

Float is 32 bits everywhere and IEEE too. Chances are it's portable enough. In general for these problems the best way is to have some "detect" logic with static: writeFile and staticExec which we should probably provide some helpers for.

2018-04-16 17:21:15

I just checked the fenv module and it is indeed using var: https://github.com/nim-lang/Nim/blob/master/lib/pure/fenv.nim#L173.

By the way, can we rename fenv to something more searchable, it's un-googlable without theindex or knowing its name.

2018-04-18 08:16:10
I'll make PR to convert these vars into consts soon 2018-04-18 11:03:18