S
surendra
hi,
i have to maintain a no of 1 bit flags.So i have two approaches
1) using bit fileds:
typedef struct flags_{
unsigned int f_1: 1;
unsigned int f_2: 2;
.
.
.
} flags;
and then i can simply set or reset these flags by
flags myflags;
myflags.f_1 = 1;
myflag.f_2 = 0 ; and so on ..
2) the other approach is to take a simple variable and write some
macros to manuplate bits in it.
unsigned int flags;
#define SET(flags, i ) (flags | (0x01 <<i))
#define RESET(flags,i) (flags &~(0x01<<i))
so the question is which way i should go ? Is there any portability
issue with bit fields.
i have to maintain a no of 1 bit flags.So i have two approaches
1) using bit fileds:
typedef struct flags_{
unsigned int f_1: 1;
unsigned int f_2: 2;
.
.
.
} flags;
and then i can simply set or reset these flags by
flags myflags;
myflags.f_1 = 1;
myflag.f_2 = 0 ; and so on ..
2) the other approach is to take a simple variable and write some
macros to manuplate bits in it.
unsigned int flags;
#define SET(flags, i ) (flags | (0x01 <<i))
#define RESET(flags,i) (flags &~(0x01<<i))
so the question is which way i should go ? Is there any portability
issue with bit fields.