Steve Underwood wrote:
In my experience, compilers typically do what mspgcc currently does now.
If you try to access an unaligned integer in a structure on a processor
which doesn't like it, they don't warn you, but the code crashes.
Really? I'm not sure I'd be impressed with that. I'm just trying to
recall what happened with PDP-11 and things in the old days.
That's
what the Alpha and MIPs compilers I have used did. Later versions of
Alpha allowed misalignment with a speed penalty, like the x86.
Yeah, but that's the hardware, not the code.
I'm not
sure if MIPs ever changed. Now, the question is, what do people really
expect on a thing like the MSP430.
If you try something like
struct
{
int x;
char y;
} xxx[10];
and loop through the array accessing x, all is well. If you pack the
structure it fails with mspgcc. The only real difference in the
generated code is the loop steps 3 bytes at a time instead of 4. Now, if
you try this with the IAR compiler for the MSP430, things still work
with the packed structure. However, to achieve that complex code is
produced when the structure is packed, and simple code is produced when
it is not. Is this something people would like to see in mspgcc?
It's an interesting dilemma. My opinion is that it should do what the
IAR compiler does, but generate a warning. Alternatively, fail to
compile with an error message explaining the issue.
The big thing about compiling for compact embedded environments where
the MSP430 is often found is that there just isn't the code space to
allow code bloat due to possible user mistakes like packing
inappropriate structs. A warning would be the least I'd expect.
Steve.