Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: [lpc2000] Re: For C Experts

2006-03-31 by Robert Adsett

At 11:49 PM 3/30/06 +0000, dsidlauskas1 wrote:
>ints are not always word aligned. For example:
>
>#pragma packed(1)
>struct eg
>      {
>      char x;
>      int y;
>      char z;
>      int w;
>      }test;
>
>One of the integers in this structure is not word word aligned and yet

Only if the compiler understands pragma packed(1) to mean byte alignment in 
the following structure.  Far from a sure thing. The compiler is quite 
allowed to insist that items be aligned on particular boundaries and for 
certain architectures to get decent performance they must.  Code that 
depends on the alignment is at the very least non-portable.  If you are 
porting from an 8 bit compiler as you indicated in another post then you 
also have to worry about sizes.  the size of that structure on an compiler 
in the most common 8 bit implementations would be 6 bytes.  On an ARM 
implementation it would be 16 bytes (6 of them would be padding).  If the 
compiler happened to understand the pragma it might bring it down to 10 bytes.

Robert

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.