What exactly does repr(C) mean on an enum?

Given that the size of an enum in C is implementation defined, what is the size of a repr(C) enum in rust? Is it always the size of a c_int? Or do we let the llvm backend pick the size?

I'm wondering how ffi-safe repr(C) enums actually are. If I was to build a rust library with extern "C" functions which take enums, how reliably could I call those functions from C programs built with various different toolchains? Are enums any less safe than structs in this regard? I ask because the author of cbindgen seems to think they are: https://github.com/eqrion/cbindgen/issues/8

Note the following warning there:

While the C standard doesn't mandate enum representation, the ABI LLVM is targeting does. For example, the AMD64 System V ABI describes the representation on page 13 here: Intel Developer Zone

3 Likes

@sfackler Ah excellent! That's good to know.