c2nim
c2nim copied to clipboard
C `enum` should not be translated to Nim enum
These have different semantics - nim enum are in particular a lot more strict than those of C - specially when they have holes or are used as flags, ie
typedef enum {a = 0x01, b = 0x02, c = a || b} flag;
void f() {
flag v = flag(42);
};
The better way to map enum to nim is via constants and type EnumType = cint - this can be done with various amounts of machinery around it (distinct, overloaded and etc) - this raises awareness in code that uses the mapped API that they need to be careful around conversions to/from the enum and other pitfalls.