[New-bugs-announce] [issue44727] Stable ABI should avoid `enum`

Petr Viktorin report at bugs.python.org
Fri Jul 23 11:23:37 EDT 2021


New submission from Petr Viktorin <encukou at gmail.com>:

Adding a new enumerator to a C enum can change the size of the type,
which would break the ABI.
This is not often a problem in practice, but the rules around when it is a problem and when it isn't are complicated enough that I believe enum should not be used in the stable ABI (possibly with well-reasoned exceptions)

AFAICS, the rules are:
- In C++, an incompatible change to an enum is one that changes the size of the *smallest bit field large enough to hold all enumerators*. Values outside the range cause undefined/unspecified behavior.
- In C, it looks like enums that fit in `char` are safe.

(Also, the compiler-defined size of enums will make it more cumbersome to formally define an ABI for non-C languages.)

----------
components: C API
messages: 398067
nosy: petr.viktorin
priority: normal
severity: normal
status: open
title: Stable ABI should avoid `enum`

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44727>
_______________________________________


More information about the New-bugs-announce mailing list