Hi

Any unaligned struct members *and* structures themselves on
RISC generally, i guess. Better to ask developers. There is an
alternative -- byte by byte access.

I don't understand.  An "alternative" to what?  It's what gcc
does on other targets when accessing misaligned packed struct
members.

I noticed some time ago that there is some problem with GCC and pointers to structures and indexes, its a bug in how gcc handles structures and should compile to the correct code, but does not. The compiler should compile what you ask of it, if it does not its a bug. The original post this seemed to be the case. Give us a test case of code that does not work and it might be fixable, without that I don't know what is wrong.

This is independent of how data is aligned in memory.

But how efficient it can be? Better to have good _design_
right from the start.

If you don't get to define the layout of the data in memory, I
don't see how you can "design" your way around doing byte by
byte access of misaligned values.

ok,

char array[128] is always in sequence and you have control of how that is aligned in memory. You put them in in sequence and incrementing a pointer to them always gets you the characters in sequence.

now,

struct
{
        char x;
        int y;
        char z;
        long b;
        char v[128];
}

Can be in any sequence the compiler likes to lay it out, even 'packed' (use minimum memory). Incrementing a pointer to this struct will not always get you x then y high, y low etc... It depends on the machine, the compiler, the final alignment in memory etc. C says thats its upto the compiler how to lay this out in memory. Its non portable, yes a lot of examples make this mistake, but its not how ANSI C is specified.

If you want to control the layout in memory then use an array. It should not matter what the layout is in memory for your code to work. If your using pointers to type cast between variable types (or structs) then you should be carful, type casting with pointers is dangerous, and the compiler tries to warn you of this where it can.

My 2C's worth.

--
Peter Jansen
STS
Antarctic Division
203 Channel Highway
Kingston
TAS  7050
AUSTRALIA
Phone +61 3 6232 3533

___________________________________________________________________________

   Australian Antarctic Division - Commonwealth of Australia
IMPORTANT: This transmission is intended for the addressee only. If you are not 
the
intended recipient, you are notified that use or dissemination of this 
communication is
strictly prohibited by Commonwealth law. If you have received this transmission 
in error,
please notify the sender immediately by e-mail or by telephoning +61 3 6232 
3209 and
DELETE the message.
       Visit our web site at http://www.antarctica.gov.au/
___________________________________________________________________________

Reply via email to