Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C enum should not be translated to Nim enum #271

Open
arnetheduck opened this issue Sep 12, 2023 · 0 comments
Open

C enum should not be translated to Nim enum #271

arnetheduck opened this issue Sep 12, 2023 · 0 comments

Comments

@arnetheduck
Copy link

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.

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

No branches or pull requests

1 participant