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

Prefer explicitly-sized ints over enums #131

Open
pitrou opened this issue Oct 26, 2023 · 0 comments
Open

Prefer explicitly-sized ints over enums #131

pitrou opened this issue Oct 26, 2023 · 0 comments

Comments

@pitrou
Copy link
Contributor

pitrou commented Oct 26, 2023

Using enums in a C ABI can make it harder for non-C languages to cooperate, as they have to find out the enum bitwidth when implementing the ABI. Granted, the enum bitwidth is normally set by the platform ABI, but people still have to find that information and perhaps write platform-specific code to handle it correctly. Using explicitly-sized ints (such as int32_t etc.) instead of enum-typed struct fields would avoid that issue.

FTR, x86-64, which I assume is the dominant platform for DLPack, mandates 32-bit integers for enums both on the "SysV ABI" (used by Linux, macOS...) and Windows. So, doing this change while minimizing potential breakage would probably require adopting int32_t fields in structs where enum fields where used.

(this does not forbid the existence of an enum declaration in the C header, btw; just in struct fields)

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