cbindgen icon indicating copy to clipboard operation
cbindgen copied to clipboard

Should `packed` attribute be used for enums with base integer type specified?

Open KOLANICH opened this issue 3 years ago • 1 comments

packed attribute (works in gcc and clang) for enums makes them to consume the minimal possible amount of bytes (and it works) and static analyser of Rust won't allow a value overflowing the type. Also it was proposed to allow use C++-style specification of base type, but it doesn't work in both Clang and gcc for now (they parse the source well (since C++ are treated there as a dialect of C), but enums are still 4 bytes in that case).

This has a benefit that enums are kept as enums.

KOLANICH avatar Aug 31 '22 11:08 KOLANICH

You mean for enums with no base integer type specified? Those don't have a c++ compatible layout afaict.

Could you provide a sample rust code, with what we generate vs. what you expect?

emilio avatar Apr 15 '24 01:04 emilio