On Tuesday 27 October 2009 02:54:50 Ricard Wanderlof wrote:
> On Mon, 26 Oct 2009, Rob Landley wrote:
> > ... Also, in my experience _Bool is about as real-world useful as the
> > bit field notation with the colons, and is really there to keep the
> > language pedants and the c++ guys happy without actually accomplishing
> > much. I've never seen it actually produce better code.
>
> It can produce more readable, less error-prone C code though. We use
> hardware register definitions such as
>
> typedef struct {
> unsigned int x : 8;
> unsigned int y : 8;
> unsigned int control_bit : 1;
> unsigned int dummy1 : 15;
> } reg_foo;
>
> at great length for the C definitions for the registers in our chips, and
> it really does avoid nasty errors that crop up when using shifting and
> masking.
And introduces new nasty errors when "unspecified by the standard" details such
as endianness change. A quick google produced:
http://bytes.com/topic/c/answers/168169-whats-memory-layout-bit-field-struct-
little-endian-big-endian-platform.
http://groups.google.com/group/gnu.gcc.help/browse_thread/thread/747918655affa5c0
Even today, gcc refuses to take a position on that one, just "determined by
ABI".
http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Structures-unions-enumerations-
and-bit_002dfields-implementation.html#Structures-unions-enumerations-and-
bit_002dfields-implementation
You're fine if all the world's a VAX, but uClibc, busybox, and the Linux kernel
tend to like working on things like powerpc and mips.
Rob
--
Latency is more important than throughput. It's that simple. - Linus Torvalds
_______________________________________________
uClibc mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/uclibc