On Jul 9, 6:24 pm, santosh <santosh....@gmail.comwrote:
Tehn Yit Chin wrote:
Does anyone know of an equivalent macro to offset() that would work
for bit fields?
eg,
struct abc
{
enable: 1;
disable: 1;
speed: 6;
};
enable_bit_position = offset_bit(struct abc, enable);
The address of bit-fields may not be taken. What is it that you actually
want to accomplish? Perhaps there may be a way other than you imagine.
I am doing some investigation on ways which the bit field could be
modified.
For example, given a more complex structure such as
struct speed_tag
{
union
{
unsigned int speed;
struct speed_part
{
unsigned int left_wheel:4;
unsigned int right_wheel:4;
}
}
}
struct speed_tag my_car;
/* access the member directly */
my_car.speed_part.left_wheel = current_speed;
/* another way of accessing */
my_car.speed &= 0x0f;
my_car.speed |= current_speed << 4;
/* what I am looking for is */
my_car.speed &= 0x0f;
my_car.speed |= current_speed << offset_bit(struct speed_part, speed);
I realise that this technique is only applicable to the platform it is
targeted for and, at this level, portability is not possible.
Cheers,