1753747 Members
5006 Online
108799 Solutions
New Discussion юеВ

Alignment issue

 
SOLVED
Go to solution
bradm_1
New Member

Alignment issue

Hello all,

I've run into what appears to be a bug in the compiler on HP 11.23.

The following program receives BUS_ADRALN - Invalid address alignment:

#include
#include

typedef struct S1
{
int val;
} S1;

static S1 *s;
static char buff[32];

int
main(int argc, char *argv[])
{
int work;

s = (S1 *)&buff[2];

s->val = 5;

work = s->val;
work += 2;
s->val = work;

printf("1. val=%d\n", s->val);

s->val += 2;

printf("2. val=%d\n", s->val);

return (0);
}

As expected, it crashes on the first reference to s->val since it is not on a four byte boundary.

I recompiled with +u1 and it gets past the first part okay, however it still crashes on the line that adds a value to s->val:

s->val += 2;

I produced an assembly listing and saw that a series of st1 and ld1 instructions were substituted for the st4 and ld4 to fix the initial problem however the line that adds 2 to the s->val is still using st4 and ld4 to move the value between memory and a register which is causing the crash.

Does anyone have any insight to this? Is it a reported problem? Am I doing something wrong?
Thanks

3 REPLIES 3
Dennis Handly
Acclaimed Contributor
Solution

Re: Alignment issue

>a bug in the compiler on HP 11.23.

What version?
This works on obsolete aCC5, A.05.50 and also OK on the latest A.06.25.02.

But it does fail on A.06.00 through A.06.02.

>Am I doing something wrong?

You are using an obsolete compiler. You need to upgrade.
bradm_1
New Member

Re: Alignment issue

Yes, I am using A.06.00

Thank you very much Dennis
bradm_1
New Member

Re: Alignment issue

Dennis Handly confirmed that this was an issue with an older compiler.