Complex Data Types 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
Primitive types Numeric Boolean Character strings Ordinal
Numeric Types Range and Precision Integer Real Decimal
Boolean
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
Strings (continued) Evaluation Implementation 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
Ordinal Enumeration Subrange
Arrays
Arrays Definition Mapping Memory allocation Slices Associative arrays Row major or column major Memory allocation Static Fixed stack dynamic Stack dynamic Heap dynamic Slices Associative arrays Operations
Records
Records Definition Mapping Operations Faster than array subscripts Elliptical references (COBOL, PL/I) Operations Move corresponding
Unions
Unions Definition Type checking? Useful but dangerous Not in Java Ada yes, others no Useful but dangerous
Sets Pascal, Java
Pointers
Pointers Operations Dynamic storage management or indirect addressing? 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