How to change bit-field allocation
tm_gccmail@kloo.net
tm_gccmail@kloo.net
Mon Sep 13 09:09:00 GMT 2004
On Mon, 6 Sep 2004, James E Wilson wrote:
> Min ZOU wrote:
> > As I know, GCC allocates bit-fields inside a structure from the lowest
> > addressed byte, i.e. LSB, for little endian. However, I want to reverse
> > the ordering for the bit-fields allocation, i.e. always from MSB.
>
> You can't change the allocation order for bit-fields without changing
> the endianness of the processor. A few moments thought should be enough
> to see the problem. The normal rule is that a bitfield goes in the
> first avaiable bit. You want it to go in the last available bit
> instead. But the last bit of what? If you want the last bit of the
> structure, then that is impossible to compute at this point because we
> don't know the size of the structure yet. If you put it in the last bit
> of the current byte, then you run into problems if you have more than 8
> bits of bitfields. If you put it in the last bit of the current word,
> then this probably works, but will add more padding then is absolutely
> necessary, and hence does not give exactly the same result as you would
> get for the other endianness.
>
> What ever you are trying to do is probably wrong. You probably should
> say what problem you are trying to solve, rather than asking how to
> implement particular solutions for it.
The SH is bi-endian.
I don't know what he's doing, but in the context of this, it may make
sense.
Toshi
More information about the Gcc
mailing list