Skip to content
  • Simon McVittie's avatar
    glib-init: statically assert that "small" enums are all int-sized · 52276300
    Simon McVittie authored
    ISO C allows compilers to make enums smaller than int if their
    enumerated values would all fit in the range of a smaller type.
    
    In practice, I suspect that in relevant compilers, all enums whose
    values fit in the range INT32_MIN to INT32_MAX (inclusive) are the same
    size as int. ISO C allows compiler to break that assumption, but those
    that do would break code that works fine in other compilers, making the
    compiler look bad, for no significant benefit. I conjecture that such
    compilers are not popular.
    
    Let's statically assert that my assumption holds. If all goes well,
    GLib will continue to compile on every relevant platform; if it
    fails to compile on some platform as a result of this change, then
    there are probably a lot of naive uses of enums that need auditing
    for this assumption.
    
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=730932
    
    
    Signed-off-by: default avatarSimon McVittie <simon.mcvittie@collabora.co.uk>
    Reviewed-by: Allison Lortie
    52276300