Stable enum tags?


A little experiment about using Rust:

It says:

Rust gives absolutely no guaranty on the internal representation of its enums. That means that when you add new variants to the enum, the actual numerical value associated to each variant might change.

Thus, userspace code compiled with one version of the source might not be compatible with a kernel compiled with another version of the code. The fact that the stdlib and the kernel are compiled at the same time and from the exact same source attenuates the problem, as long as the softwares are dynamically linked to the stdlib.

On the other hand, software statically linked might need to be recompiled to continue working. One way around might be to never change the order of the variants, and only adding new ones at the end of the enum, so the number of the preexisting ones should remain the same across versions.

If that’s a real problem can you solve it adding tag values?

enum Foo {


    Baz(f32, f32),


Even with fixed tag values, the entire layout is not a stable ABI. I think I would stick to #[repr(C)] for such interfaces.