avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Bit-wise structure and unions


From: David Gay
Subject: Re: [avr-gcc-list] Bit-wise structure and unions
Date: Wed, 22 Nov 2006 10:06:11 -0800

On 11/21/06, Eric Weddington <address@hidden> wrote:
Hi Keith

[Long time, no hear. ;-)]

Comments below.

> -----Original Message-----
> From:
> address@hidden
> [mailto:address@hidden
> org] On Behalf Of Keith Gudger
> Sent: Tuesday, November 21, 2006 11:41 AM
> To: address@hidden
> Subject: [avr-gcc-list] Bit-wise structure and unions
>
> Below is a program which illustrates the following issue:
>
<snip>

> But I would rather not have the union.  Is there any other way around
> this?  Thanks.
>

Unfortunately, no. The union would be the standard solution.

Ok, I take that back but only slightly. Why use bit fields at all? They are
inherently non-portable between compilers (if they work, then you're lucky).
Inherently, bit fields are tied to an int, which on the avr port is a 16-bit
type. We're lucky in that you can get GCC to put them into an unsigned char.
But again, that's compiler dependent.

Actually a platform ABI for C normally specifies such things precisely
to avoid same-platform different-C-compiler portability problems
(there's way more things than just bitfields that are not specified by
the C standard, so such an ABI spec is a necessity). FWIW, avr-gcc
packs bitfields into bytes. The size of int or the type used to
declare the bitfield don't affect this packing (*). Whether this
matches what IAR C is doing is another question...

David Gay
*: If you're curious, avr-gcc doesn't define the magic
PCC_BITFIELD_TYPE_MATTERS flag in its configuration.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]