How to declare an enum type with a specific size

I want to define an enum with sizeof()==1 in C without using any command line options that apply to all enums. Something like:

typedef enum { MINVAL=-128, MAXVAL=127 } E8_t;

I’d like to apply an attribute to it that would tell the compiler to make it’s size 8 bits. Is this already possible in Clang? I tried attribute((packed)) but get an error.

Thanks

I don't think we currently have a way to do this. If you can compile as C++11 or Objective-C, though, you can use a fixed underlying type:

typedef enum : signed char { MINVAL=-128, MAXVAL=127 } E8_t;

I don't think it would be out of line to consider allowing this as an extension in C modes, but someone else should chime in on that.

Jordan