[oe] need help: cdrkit & bitifields

Frans Meulenbroeks fransmeulenbroeks at gmail.com
Fri Mar 6 09:42:18 UTC 2009


2009/3/6 Phil Blundell <pb at reciva.com>:
> On Thu, 2009-03-05 at 22:10 +0100, Frans Meulenbroeks wrote:
>> main(int argc, char **argv)
>> {
>>     char c = 0xf0;
>>     bitfields *bf = &c;
>
> This isn't a legal thing to do.  Struct addresses on ARM need to be
> 32-bit aligned, whereas &c is only guaranteed aligned to an 8-bit
> boundary.  You can't, in general, take a pointer to an arbitrary type,
> cast it to a struct and expect to get good results.
>
> You need to use a union, or something like:
>
> struct wrapped_char {
>        char c;
> }
>
> struct wrapped_char wc;
> wc.c = 0xf0;
> bitfields &bf = &wc;
>
> p.
>

Hi Phil,

I understand the alignment issue.
However the problem occurs in code that I have not written and that is
not easy to modify.
I don't have the code handy but it could be that the code in cdrkit
works just the other way:
E.g. something like:
bitfields bf;
char *p = &bf;
*p = 0xf0;

I'll test that variant as well.
The stupid thing is that cdrkit words under opensuse/x68 but not under
oe/arm (LE).
So either this is a compiler issue or a nonportable construct.

Puzzled.
FM




More information about the Openembedded-devel mailing list