E
Eric Sosman
Neo said:typedef union
{
struct
{
UINT16 reserved : 14;
UINT16 bank_no : 2;
} bit;
UINT16 word;
} HSL_BANK_SELECT_T;
HSL_BANK_SELECT_T a;
a.bit.bank_no = 1
Is bank_no MSB or LSB?
Either. Or neither. The compiler has wide discretion
in the way it arranges bit-fields, and different compilers
do it differently.
What is the significance of UINT16 or any other type here?
The legitimate types for bit-fields are signed and
unsigned `int' and (in C99) _Bool. A compiler may accept
other types as well, but is not required to do so -- which
means that the next compiler you use might not accept these
extensions.
Since you haven't shown how UINT16 is defined, it's
not possible to say whether it's a legitimate bit-field
type. You may be in trouble already.
Can I replace it with UINT8 or UINT32.... arbitrarily?
See above.
typedef union
{
struct
{
UINT16 reserved : 14;
UINT16 bank_no : 2;
UINT8 some_flag1 : 1;
UINT8 some_flag2: 1;
} bit;
UINT32 word;
} HSL_BANK_SELECT_T2;
Is this valid to have UINT16 and UINT8 intermixed...???
See above.
You have fallen into a trap that has caught many before
you, namely, of thinking that `struct's, with or without
bit-fields, are a means of mapping an externally-imposed
format. Such use may be appropriate for a particular compiler
on a particular machine, but the language definition does not
guarantee that the mapping will be as you hope.