Nicolas Pitre wrote:
> On Thu, 14 Sep 2000, Gordon McNutt wrote:
>
> > George France wrote:
> >
> > > Correction:
> > >
> > > struct foo_t { u16 x; } __attribute__ ((packed));
> > >
> > > Best Regards,
> > >
> > > --George
> >
> > I hope it's something that simple. But the following example makes me
> > worry that it is not, as this example does not use structs:
> >
> > u8 buf[4];
> > u16 *a;
> > a = &buf[1];
> > *a = 4;
>
> This is the perfect example of what you can't do on any ARM processor (nor
> Alpha nor IA-64, etc.) because alignment is important. Many applications
> were written with i386 CPUs in mind where alignment isn't an issue, but
> this is bad practice and not portable.
>
> Nicolas
I think I have a solution that will work for me:
struct u16_t { u16 a ; } __attribute__ ((packed));
...
u8 buf[4];
struct u16_t *a ;
a = (struct u16_t*)&buf[j];
a->a = 4;
I can't use the __attribute__ directives on a built-in type or a typedef
like u16 (if I understand the gcc documentation correctly), but I can wrap a
type in a struct and apply the directive to the struct. Then, the ARM code
works exactly like the i386. This works regardless of wether j is odd or not.
Received on Fri Sep 15 08:12:46 2000
This archive was generated by hypermail 2.1.8 : Tue May 04 2004 - 09:43:42 EDT