lec10 - CS240: Programming in C Lecture 10: Review -...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
CS240: Programming in C Lecture 10: Review - Structures and Memory Allocation Unions Monday, February 21, 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Recap: Structures Holds multiple items as a unit Treated as scalar in C: can be returned from functions, passed to functions They can not be compared A structure can include a pointer to itself, but not a member of the same structure a member of another structure, the latter has to have the prototype declared before Allocation of memory for structure’s fields must respect alignment as dictated by the underlying architecture Monday, February 21, 2011
Background image of page 2
Structure recap Member access Direct: s.member Indirect: s_ptr->member Dot operator . has precedence over indirect access operator -> What does s.t->u mean? How about (s.t) -> u? Or, s.(t->u)? Is there a difference between (*s).t and s->t? Monday, February 21, 2011
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Data alignment: when the processor accesses the memory reads more than one byte, usually 4 bytes on a 32-bit platform. What if the data structure is not a multiple of 4? Padding. Implementations must typically handle alignment. Monday, February 21, 2011
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 16

lec10 - CS240: Programming in C Lecture 10: Review -...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online