-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Proposal: add -fshort-enums
support to translate-c
#8662
Comments
Not only for translate-c but I think we should also add support for it in the main CLI options as well, but make it clear that it applies only to compiled C code. I think if you go to implement this it will become clear that these features are intertwined. |
Are you suggesting that instead of doing this in translate-c; have a CLI option |
Wait a minute, sorry, I just realized this should already be working, like this:
I tried it just now and it did not affect the output, but that seems like a bug. Not sure why that is happening. I'm guessing the translate-c code is doing its own logic to determine the int tag of generated enums but it should be asking the Clang API for the integer type. Semi-related: 557eb41 |
Ah ok, it might just be a bug in the cli parsing then. I just tested it out and |
Fixes the issue identified in ziglang#8662
Additionally ensure that the Zig cache incorporates any extra cflags when using translate-c. Fixes the issue identified in ziglang#8662
Closed in favor of #8676 |
Additionally ensure that the Zig cache incorporates any extra cflags when using translate-c. Fixes the issue identified in #8662
GCC & Clang have a command-line option
-fshort-enums
that can be used to control how many bytes are allocated for an enum type. It's equivalent to putting__attribute__((packed))
on all enums. From the GCC docs:Super basic demonstration, compare output of the following C program when compiled with
-fshort-enums
vs not:The relevance to translate-c is that enum sizes affect ABI compatibility. Currently translate-c always translates enums with an underlying type of
c_int
orc_uint
, but this won't work if linking with code that was built with-fshort-enums
. Short enums are fairly common in embedded systems where space is at a premium.One way to solve this would be to add a special preprocessor symbol like
__ZIG_SHORT_ENUMS
(which can be used withzig translate-c
via-D__ZIG_SHORT_ENUMS
, and can be used with@cImport
via@cDefine("__ZIG_SHORT_ENUMS", {});
. translate-c could look for the existence of that symbol and use it to control whether enums are generated with the short enum algorithm described above. One downside to this approach is that it reifies the short enum decision into the generated code, so it wouldn't be possible to translate code once and have it automatically work across platforms.The text was updated successfully, but these errors were encountered: