Instead the compiler will allocate 12 bytes for

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: o that of arrays in that all of the components of a structure are stored in a contiguous region of memory, and a pointer to a structure is the address of its first byte. The compiler maintains information about each structure type indicating the byte offset of each field. It generates references to structure elements using these offsets as displacements in memory referencing instructions. New to C? The struct data type constructor is the closest thing C provides to the objects of C++ and Java. It allows the programmer to keep information about some entity in a single data structure, and reference that information with names. For example, a graphics program might represent a rectangle as a structure: struct rect { int llx; int lly; int color; int width; int height; }; /* /* /* /* /* X coordinate of lower-left corner */ Y coordinate of lower-left corner */ Coding of color */ Width (in pixels) */ Height (in pixels) */ We could declare a variable r of type struct rect and set its field values as follows: 154 CHAPTER 3. MACHINE-LEVEL REPRESEN...
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