Solved

How much space is reserved for type enum?

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

758 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

24 Experts available now in Live!

Get 1:1 Help Now