tags:

views:

166

answers:

2

Hi All,

If i declare an enum as follows:

typedef enum A
{
    a = 0x00000001,
    b = 0x00000002
} AObj;

Now if i declare a variable of AObj as follows what does this mean?

AObj myAObj : 2;
+4  A: 

It is a way of specifying the number of bits used. That is 2 means 2 bits.

Also note that this is only useful when used with other bit fields in the same struct as alignment and padding will cause the memory to be skipped.

Dave Hillier
+4  A: 

You are probably talking about "bit fields" which enables you to create a struct in which you can address individual bits. But (unless I am mistaken!) your syntax is all wrong: you are missing commas and equals signs in your enum:

    typedef enum A
    {
       a = 0x00000001,
       b = 0x00000002
    } AObj;

More importantly, bitfields are declared inside of structs, so it's not entirely clear what you're trying to do.

(Or is this use of the colon some other syntax I'm not aware of???)

Andrew Jaffe
hi, thanks for the answer, actually i had to put a ',' not ';' inside the enum. And i guess the answer given down is what i was seraching for.
Raghu