3

C++11 lets you explicitly specify the underlying type of an enum, e.g.

enum Status : uint8_t
{
    OK = 0,
    BAD = 1,
};

Does any version of C provide a similar feature?

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
Timmmm
  • 88,195
  • 71
  • 364
  • 509
  • Also http://stackoverflow.com/questions/43039534/forcing-the-size-of-an-enumd-field-in-a-structure#comment73170767_43039534 – StoryTeller - Unslander Monica Mar 28 '17 at 09:43
  • 1
    @PSkocik enum constants are `int`, enum type is implementation-defined integer type (may be other than `int`). – user694733 Mar 28 '17 at 10:01
  • @user694733 Thanks for the correction. I assume it can't be larger, than int, though, given that "The expression that defines the value of an enumeration constant shall be an integer constant expression that has a value representable as an int." and "The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration." – Petr Skocik Mar 28 '17 at 11:13

0 Answers0