However the location of character array buf is

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: te allocation, diagrammed as follows: Offset Contents 0 i 4 c 5 j Then it would be impossible to satisfy the 4-byte alignment requirement for both fields i (offset 0) and j (offset 5). Instead, the compiler inserts a 3-byte gap (shown below as “XXX”) between fields c and j: Offset Contents 0 i 4 c 5 XXX 8 j so that j has offset 8, and the overall structure size is 12 bytes. Furthermore, the compiler must ensure that any pointer p of type struct S1 * satisfies a 4-byte alignment. Using our earlier notation, let pointer p have value Üp . Then Üp must be a multiple of 4. This guarantees that both p->i (address Üp ) and p->j (address Üp · ) will satisfy their 4-byte alignment requirements. In addition, the compiler may need to add padding to the end of the structure so that each element in an array of structures will satisfy its alignment requirement. For example, consider the following structure declaration: struct S2 { int i; int j; char c; }; If we pack this structure into 9 bytes, we can still sati...
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