Hi,

Packed structures definitely have their use. For example when you
exchange data between different architectures (networks, etc.) Yes, you
take a performance hit in memory access, but in many case you will find
out that it is just a matter if it is you who pack/unpack it manually or
a compiler doing it for you. I agree that sometimes you can play games
with structure member ordering but it is not always up to us to decide
on it (e.g. foreign data). 

BTW, I believe default structure packing/ordering is not specified by
any standard (?) - it is "try and see" what the compiler did.

Sergei 

> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf 
> Of [email protected]
> Sent: Tuesday, January 04, 2005 5:59 AM
> To: [email protected]
> Subject: RE: [Mspgcc-users] Problem with packed structures..
> 
> 
> Hi,
> 
> >    In reply to Chris' post - The IAR compiler handles such 
> structures by
> > accessing the data byte by byte. So, assigning the value, 
> 0x1234 to "hg.b"
> > (odd memory location) is done one byte at a time, i.e. 0x34 
> is moved in
> > first and then 0x12 is moved into the next higher byte. As 
> Chris rightly
> > pointed out, it would've been nice if mspgcc could generate 
> similar code :-)
> 
> i don't agree because a) this produces more (assembler) code 
> which needs more flash,
> b) it's slower and c) it's not necessary when you do define 
> your struct as
> 
> {
> int i;
> char c;
> }
> 
> instead of the ugly
> 
> {
> char c;
> int i;
> }
> .
> You should follow the generally rule that a struct should 
> start with the greatest member and that the
> member n should be smaller or equal then member n-1. But you 
> also have to bear in mind
> the alignment.
> 
> Regards,
> 
> Rolf
> 
> 
> 
> 
> -------------------------------------------------------
> The SF.Net email is sponsored by: Beat the post-holiday blues
> Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
> It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
> _______________________________________________
> Mspgcc-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
> 

Reply via email to