
In message 426DDE65.4060009@intracom.gr you wrote:
...which is broken, especially when there is no need to do this since the fields are properly aligned.
The compiler does not know this. A pointer to the structure could be pointing to an non-aligned address, and when an aligned field within the structure is accessed it will be not aligned.
This is no reason for anything. The same could be true for ANY structures, even without using the packed attribute. It is the user's problem if he passes incorrectly aligned pointers.
This typically happens when networking.
Yes, and usually you will have to explicitely deal with this.
IMHO __attribute((packed)) is deceivingly named, since it implies two things.
I think you are wrong. You are trying to explain the current imple- mentation of GCC for ARM, assuming silently that the implementation is correct. I say: it is broken.
- Don't leave any space between fields of the structure.
Correct - this is what the documentation says:
The `packed' attribute specifies that a variable or structure field should have the smallest possible alignment--one byte for a variable, and one bit for a field, unless you specify a larger value with the `aligned' attribute.
Here is a structure in which the field `x' is packed, so that it immediately follows `a':
struct foo { char a; int x[2] __attribute__ ((packed)); };
- Access the fields of the structure even when the alignment of the pointer pointing to it is wrong.
Wrong. Remember that a structure may be a representation for things like hardware registers. Registers may have funny properties, like auto-incrementing with each access, or auto-resetting on read. If I perform a 32 bit read on such an object the compiler MUST NOT break this up into any other combination of accesses.
Just by the name, you expect only (1).
By the name, and the documentation, and common sense.
I think we have covered all relevant facts now. I understand that we won't have GCC fixed soon, and I already suggested what I think should be used to work around this compiler bug (using aligned).
Best regards,
Wolfgang Denk