{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

1402 13 - COMP1002/1402 Chapter13:DerivingTypesII...

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

View Full Document Right Arrow Icon
1/31/2010 1 COMP 1002/1402 Introduction to Systems Programming Chapter 13: Deriving Types II Notes Adapted from Dr. J. Morrison, Dr D. Nussbaum Nesting Structures So far, only basic types appeared in struct Question : Why not defined types? Answer : No reason. Simplicity of presentation 2 COMP1002/1402 - Chapter 12: Deriving Types II
Image of page 1

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

View Full Document Right Arrow Icon
1/31/2010 2 Nesting Structures Define a STAMP to contain: a DATE and a TIME 3 COMP1002/1402 - Chapter 12: Deriving Types II How to do it Use one struct or type inside the overall struct See following examples... Style :Declare every structure separately! Necessity : Declare before use. 4 COMP1002/1402 - Chapter 12: Deriving Types II
Image of page 2
1/31/2010 3 Bad Style typedef struct { struct { int month; int day; int year; } date ; struct { int hour; int min; i t int sec; } time ; } STAMP ; STAMP aStamp; 5 COMP1002/1402 - Chapter 12: Deriving Types II Good Style typedef struct { int month; int day; int year; } DATE ; typedef struct { int hour; int min; int sec; } TIME ; typedef struct { DATE date; TIME time; } STAMP ; STAMP aStamp ; 6 COMP1002/1402 - Chapter 12: Deriving Types II
Image of page 3

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

View Full Document Right Arrow Icon
1/31/2010 4 Referencing Nested Structures aStamp aStamp . date aStamp . date .month aStamp . date .day aStamp . date .year aStamp . time aStamp . time .hour aStamp . time .min aStamp . time .sec 7
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.