DSPRelated.com
Forums

Help Needed on Alignment Issue with CCS V1.3 and ARM7

Started by Glenn Shirley December 16, 2003
I've got an odd alignment issue I need some help with. I'm using CCS V1.3
with an ARM7 as my target.

I have three structures:

struct Z_T
{
u16 a;
u16 b;
};

struct Y_T
{
u8 c
u8 d;
Z_T e;
};

struct Z_T
{
elephant f; /* seem to be irrelevant what these are */
cow g;

Z_T h;
};

Now if may code is effectively:

Y_T m;
Z_T *n;

n->h.a = 53;
n->h.b = 0;

m.c = 1;
m.d = 1;

m.e = n->h;

After this line m.c and m.d actually contain 53 and 0 (the contents of
n->h). m.e actually contains incorrect value and I'm still trying to work
out where they come from.

If I change the u8s in Y_T to u16 the problem goes away. If I pad Z_T with
a u8 the problem goes away.

So is the last line of my code a dodgy piece of coding that should be
avoided?

Is this possibly caused by some optimisation that's occurring? (I've tried
the same thing with all optimisation off and it still occurs).

Are there some other compiler switches/project options which could be
causing this?

I can easily fix this by assigning each member of the struct Z_T
individually but I'd rather not have to change this sort of thing throughout
lots of files.

Any help appreciated!

Cheers,
Glenn.