- May 1, 2012
- 21
- 0
- 61
Hello.
I am currently updating a project that uses bitfields heavily. To do this I am planning to use these as well. My question is if the following is correct, appropriate or a good idea:
first a field in the bitfield:
Yeah, I know the standard recommends only use unsigned ints for that, but for some reason the project uses a user defined WORD.
Ok, so I have a 2-bit field so I guess it means this can assume 4 values right?
So I define something like
So, my question is , can I safely do something like
or even
any advice will be greatly appreciated
Thanks
Kansai
I am currently updating a project that uses bitfields heavily. To do this I am planning to use these as well. My question is if the following is correct, appropriate or a good idea:
first a field in the bitfield:
Code:
struct {
WORD somefield:1;
WORD otherfield :1;
WORD MYFIELD:2; // The 2-bit field I am going to use
} somebitfield;
Yeah, I know the standard recommends only use unsigned ints for that, but for some reason the project uses a user defined WORD.
Ok, so I have a 2-bit field so I guess it means this can assume 4 values right?
So I define something like
Code:
enum { NOTHING=0, STATEONE, STATETWO,STATETHREE} myenum;
So, my question is , can I safely do something like
Code:
if(somebitfield.MYFIELD==NOTHING) {
}
elseif (somebitfield.MYFIELD==STATETWO){
}
or even
Code:
switch(somebitfield.MYFIELD)
{
case NOTHING:
case STATEONE:
}
any advice will be greatly appreciated
Thanks
Kansai