Re: Help with cross-endian bitfields?

2 messages, 2 authors, 2000-05-08 · open the first message on its own page

Re: Help with cross-endian bitfields?

From: james woodyatt <hidden>
Date: 2000-05-08 07:03:57

Daniel Jacobowitz [off-list ref] wrote:
On Fri, May 05, 2000 at 03:27:21PM -0400, jlquinn@us.ibm.com wrote:
quoted
[...]
quoted
Can someone tell me what's going on here?  Am I going to have to have
ifdef's on these structs, or resort to mask macros, or is there a
reasonable solution here.
As Dan Malek said, there is no defined ordering.  The compiler is free
to do whatever it wishes.  You can't assume that.  (I think.)
[...]

It's absolutely true.

Not only is there no defined ordering, the ANSI standard says that it
doesn't even need to use bitfield operations in the machine code.  It's
allowed to pad arbitrarily between the bitfields.  It's allowed to
completely ignore the bitfield widths and treat the members like integers.
It's even allowed to order the very bits themselves in weird ways, if it
thinks the processor will like it better that way.

Bitfields are just not even remotely portable.

C structures should not be used to represent portable serializations of
external data.  Period.  Yes, they're convenient-- but your compiler and my
compiler don't have to agree on practically anything about them.


--
j h woodyatt [off-list ref]
http://www.wetware.com/jhw
"Yeah, Mercury's going into retrograde, but
at least we're not the Kennedys."  --sean poreda


** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

Re: Help with cross-endian bitfields?

From: Geert Uytterhoeven <geert@linux-m68k.org>
Date: 2000-05-08 09:50:49

On Mon, 8 May 2000, james  woodyatt wrote:
Daniel Jacobowitz [off-list ref] wrote:
quoted
On Fri, May 05, 2000 at 03:27:21PM -0400, jlquinn@us.ibm.com wrote:
quoted
[...]
quoted
quoted
Can someone tell me what's going on here?  Am I going to have to have
ifdef's on these structs, or resort to mask macros, or is there a
reasonable solution here.
As Dan Malek said, there is no defined ordering.  The compiler is free
to do whatever it wishes.  You can't assume that.  (I think.)
[...]

It's absolutely true.

Not only is there no defined ordering, the ANSI standard says that it
doesn't even need to use bitfield operations in the machine code.  It's
allowed to pad arbitrarily between the bitfields.  It's allowed to
completely ignore the bitfield widths and treat the members like integers.
It's even allowed to order the very bits themselves in weird ways, if it
thinks the processor will like it better that way.

Bitfields are just not even remotely portable.

C structures should not be used to represent portable serializations of
external data.  Period.  Yes, they're convenient-- but your compiler and my
compiler don't have to agree on practically anything about them.
And we all use gcc to compile Linux kernels... So the only remaining issue is
endianness.

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- Linux/{m68k~Amiga,PPC~CHRP} -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds


** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help