Heterogeneous Data Structures Alignment heterogeneous:不同种类的
1 Heterogeneous Data Structures & Alignment * heterogeneous: 不同种类的
Outline Struct Uu nion Alignment -chqp3.93.10
2 Outline • Struct • Union • Alignment – Chap 3.9, 3.10
Structures P191 Group objects into a single object Each ob ject is referenced by name Memory layout All the components are stored in a contiguous region of memory a pointer to a structure is the address of its first byte References to structure elements Using offsets as displacements
3 Structures P191 • Group objects into a single object • Each object is referenced by name • Memory layout – All the components are stored in a contiguous region of memory – A pointer to a structure is the address of its first byte • References to structure elements – Using offsets as displacements
Structure P192 struct rect in七11x; /*x coordinate of 1。wer-1 eft corner*/ in七1 /* y coordinate of 1。wer-1 eft corner★ int color /★ Coding ofco1ox*/ int width; /* width (in pixels)*/ int height / Height (in pixels)*/
4 Structure P192 struct rect { int llx; /* X coordinate of lower-left corner */ int lly; /* Y coordinate of lower-left corner */ int color; /* Coding of color */ int width; /* Width (in pixels) */ int height; /* Height (in pixels) */ };
Structure P192 struct rect ri r.11x=x.11y=0; r color oxFFooFF r width = 10; rheight 20;
5 Structure P192 struct rect r; r.llx = r.lly = 0; r.color = 0xFF00FF; r.width = 10; r.height = 20;