CS 342 Lecture -*- Outline -*- * Data Structures ** Kinds of data structures *** primitives no components (integers, enumeration types...) *** structured types have components that are other data (arrays, records) structured types are second-class citizens ** Types designed for security and efficiency enumeration types, subrange types, set types, ... ** Problems with Pascal Types *** feature interaction problem for arrays **** cannot write programs that work on arrays of different sizes (in original Pascal) -dimensions of array part of type -actual parameters must match formals e.g. cannot write sort procedure that sorts arrays of integers with different index types **** solution adopted in ISO Standard Pascal allow conformant array schemas as types for formals: --------------- array[lwb..upb: integer] of real -------------- is type of real arrays indexed by integers; binds lwb to lower bound and upb to upperbound still can't write sort that works on all arrays *** Security of variant records useful when parts of record depend on data in other parts --------- record s: sign; {illustrates syntax} case op: opcode of 0,8: (addrs: array[1..2] of data_address); 1,2,3,4,5,6,7: (addrs: array[1..3] of data_address); 9: (); end end --------- **** space efficiency **** security benefit, cannot access fields that are meaningless **** security loophole no need to synchronize changing of tag with fields of variant can have variant without tag represented case typename of ... => can subvert type system, access uninitialized storage *** Pointer Security can only refer to storage for values of given type can only refer to storage on the heap (dynamic alloc) not to the run-time stack. => prevents dangling references but "dispose" (in impls only) permits dangling references!