Solved

How much space is reserved for type enum?

Posted on 2013-12-10
1
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

740 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