Jump to content
  • Advertisement
Sign in to follow this  
rKallmeyer

enumeration size

This topic is 4945 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I would like to force the compiler to allocate one byte for a specific enumeration. I googled around, and found that the HP C compiler supports the following syntax:
long long enum bigger_enum {barge, yacht}; /* 8-byte enum type */
enum default_enum {ERR1, ERR2, ERR3, ERR4};/* 4-byte enum type */
long enum big_enum {STO, ST1, ST2, ST3};   /* 4-byte enum type */
short enum small_enum {cats, dogs};        /* 2-byte enum type */
char enum tiny_enum {alpha, beta};         /* 1-byte enum type */


Unfortunetly I am using VC .net 03 which doesn't appear to support it. I am getting the following 2 compiler errors:
Quote:
c:\*** : error C2236: unexpected 'enum' 'Class::Type' c:\*** : error C2208: 'Class::Type' : no members defined using this type
Does anyone know of anyway to force the enumeration size in VC .net? Help would be much appreciated, Thanks. EDIT: cleaning up source

Share this post


Link to post
Share on other sites
Advertisement
GCC has the '-fshort-enums' switch which will cause it to use the smallest integer type that'll hold all the values. MSVC probably has an option for this somewhere, too.

Share this post


Link to post
Share on other sites
I think that VC.NET automatically uses the smallest datatype possible for the enums, hence seeing a lot of DirectX enumerations contain the following:

WHATEVER_FORCE_DWORD = 0x7FFFFFFF

Failing compiler switches, that's the method you'd probably have to resort to.

-Mezz

Share this post


Link to post
Share on other sites
In C an enum has the same size as an int. In C++ it has the size of the smallest type that will accomodate the largest value used in the enumeration.

Share this post


Link to post
Share on other sites
If you need it to be a specific size, then you should use a integer type of the right size, rather than an enum. I assume you need the specific size for portability or optimization reasons.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!