ISO C standard says that type of enum size is implementation-dependent:
Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.
Then, if we have the following situation:
- Some C library is distributed in public headers and binaries. The library provides some interfaces with enum parameters or returning enum values.
- Users compile their source files with enum declarations from public headers - a compiler on a user side might use different size of enum (from size inside the library).
It might cause binary incompatibility when passing values from user code inside the library (or vice versa) - e.g. user code would rely on int, but library code would use short - we might have problems because some bytes of an enum variable returned from the library will be uninitialized when read in the user code. So if we are relying on standard in this respect, formally we could run into such kind of issuesю
Is it correct reasoning? Especially given the fact that many C libraries are distributed in the similar way: public headers + static/shared libraries.