Solved

How much space is reserved for type enum?

Posted on 2013-12-10
1
255 Views
Last Modified: 2013-12-10
Please consider following enum type.

typedef enum ParamAttrMask{
    ParamAttrMask_None       = 0x00, // Cannot be read or writtent
    ParamAttrMask_Read       = 0x01, // Can read
    ParamAttrMask_Write      = 0x02, // Can write
    ParamAttrMask_ReadWrite  = ParamAttrMask_Read | ParamAttrMask_Write, // Readable and Writable
    ParamAttrMask_Locked     = 0x04, // Needs password to write
    ParamAttrMask_Archive    = 0x08, 
    ParamAttrMask_RunTime    = 0x10,
  } tParamAttrMask;

Open in new window



ParamAttrMask  Attributes;

How many bytes is allocated for Attributes ?  Is it one byte? Is it compiler specifice?
0
Comment
Question by:naseeam
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 39709543
It's usually more implementation-specific than compiler specific, but every compiler usually has a "treat enums as ints" option, so you can assume it usually is the same size. But, why not find out that for sure using

typedef enum ParamAttrMask{
    ParamAttrMask_None       = 0x00, // Cannot be read or writtent
    ParamAttrMask_Read       = 0x01, // Can read
    ParamAttrMask_Write      = 0x02, // Can write
    ParamAttrMask_ReadWrite  = ParamAttrMask_Read | ParamAttrMask_Write, // Readable and Writable
    ParamAttrMask_Locked     = 0x04, // Needs password to write
    ParamAttrMask_Archive    = 0x08, 
    ParamAttrMask_RunTime    = 0x10,
  } tParamAttrMask;
                                  
printf("Enum size is %d\n", sizeof(tParamAttrMask));

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question