Solved

How much space is reserved for type enum?

Posted on 2013-12-10
1
253 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
returning a dereferenced pts in C++ 10 141
Arduino EDI - Programming language 3 79
Least Squares Curve Fitting 4 57
c++, dynamic object by json 1 19
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now