Transcript Complex
Complex Data Types
(6.1)
One very important measure of the “goodness” of a
PL is the capability of its data types to model the
problem space variables
Design issues for all data types
– what is the syntax of references to variables?
– what operations are defined and how are they
specified?
Compilers use descriptors to maintain information
about instances of types in a program
– actually part of the symbol table
– what’s needed in descriptor depends on particular
type
– when the descriptor is needed depends on the kind of
type checking required
» static, compile time only
» dynamic, run-time as well
(6.2)
Primitive types
– Numeric
– Boolean
– Character strings
– Ordinal
Numeric Types
Range and Precision
– Integer
– Real
– Decimal
(6.3)
(6.4)
Boolean
(6.5)
Character string
Character String Issues
Primitive or not
– Snobol, Java primitive
– Ada, F77, F90, Basic “somewhat” primitive
– Pascal, C, C++ not primitive
Static or dynamic
– Or limited length dynamic
Operations
(6.6)
Strings (continued)
(6.7)
Evaluation
– aid to writability
– as a primitive type with static length, they are
inexpensive to provide--why not have them?
– dynamic length is nice, but is it worth the
expense?
Implementation
– static length - compile-time descriptor
– limited dynamic length - may need a run-time
descriptor for length (but not in C and C++)
– dynamic length - need run-time descriptor;
allocation/deallocation is the biggest problem
(6.8)
Ordinal
– Enumeration
– Subrange
(6.9)
Arrays
Arrays
Definition
Mapping
– Row major or column major
Memory allocation
– Static
– Fixed stack dynamic
– Stack dynamic
– Heap dynamic
Slices
Associative arrays
Operations
(6.10)
(6.11)
Records
Records
Definition
Mapping
– Faster than array subscripts
– Elliptical references (COBOL, PL/I)
Operations
– Move corresponding
(6.12)
(6.13)
Unions
Unions
Definition
– Not in Java
Type checking?
– Ada yes, others no
Useful but dangerous
(6.14)
(6.15)
Sets
– Pascal, Java
(6.16)
Pointers
Pointers
Operations
– Assignment and dereferencing
Dynamic storage management or indirect
addressing?
Scope/lifetime of pointers and associated
dynamic objects?
Problems
– Dangling references, lost objects
Storage management
– Reference counts, garbage collection
Java allows only references
– Implicit deallocation
(6.17)