[cfe-dev] How to declare an enum type with a specific size

Jordan Rose jordan_rose at apple.com
Fri Jan 17 09:33:57 PST 2014

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.


On Jan 16, 2014, at 16:03 , Mark Schimmel <marksl at synopsys.com> wrote:

> 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
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140117/de097dec/attachment.html>

More information about the cfe-dev mailing list