The c compiler even produces the following error

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: sfy the alignment requirements for fields i and j by making sure that the starting address of the structure satisfies a 4-byte alignment requirement. Consider, however, the following declaration: struct S2 d[4]; With the 9-byte allocation, it is not possible to satisfy the alignment requirement for each element of d, because these elements will have addresses Üd , Üd · , Üd · ½ , and Üd · ¾ . Instead the compiler will allocate 12 bytes for structure S1, with the final 3 bytes being wasted space: Offset Contents 0 i 4 j 8 c ·¾ 9 XXX , and Üd · ¿ . As long as Üd is a That way the elements of d will have addresses Üd , Üd · ½¾, Üd multiple of 4, all of the alignment restrictions will be satisfied. 162 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS Practice Problem 3.23: For each of the following structure declarations, determine the offset of each field, the total size of the structure, and its alignment requirement under Linux/IA32. A. struct P1 { int i; char c; int j; char d; }; B. struct P2...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online