Chapter 6 : Review Question
1. What is a descriptor?
= Descriptor is the collection of the attributes of a variable.
2. What are the advantages and disadvantages of decimal data types?
= The advantages of decimal data types is being able to precisely store decimal values, at least those within a restricted range, which can’t be done with floating-point. And the disadvantages of decimal data types are that the range of values is restricted because no exponents are allowed, and their representation in memory is mildly wasteful.
3. What are the dessign issues for character string types?
= The two most important design issues that are specific to character string types are the following :
– Should strings be simply a special kind of character array or a primitive type?
– Should strings have static or dynamic length?
4. Describe the three string length options.
= – Static length string: the length can be static and set when the string is created.
– Limited dynamic length strings: allow strings to have varying length up to a declared and fixed maximum set by the variable’s definition.
– Dynamic length strings: allow strings to have varying length with no maximum.
5. Define ordinal, enumeration, and subrange types.
= – Ordinal type is one in which the age of possible values can be easily associated with the set of positive integers. In Java, for example, the primitive ordinal types are integer, char, and Boolean.
– Enumeration and subrange are the two user-defined ordinal type that have been supported by the programming languages.
– Enumeration type is one in which all of the possible values, which are named constants, are provided, or enumerated, in the definition. Enumeration types provide a way of defining and grouping collections of named constants, which are called enumeration constants.
– Subrange type is a contiguous subsequence of an ordinal type.
Chapter 6 : Problem Set
1. What are the arguments for and against representing Boolean values as single bits in memory?
= Boolean variables stored as single bits are very space efficient, but on most computers access to them is slower than if they were stored as bytes.
2. How does a decimal value waste memory space?
= Decimal types are stored very much like character strings, using binary codes for the decimal digits. These representations are called binary coded decimal (BCD). In some cases, they are stored one digit per byte, but in others, they are packed two digits per byte. Either way, they take more storage than binary representations. It takes at least four bits to code a decimal digit. Therefore, to store a six-digit coded decimal number requires 24 bits of memory. However, it takes only 20 bits to store the same number in binary.
3. VAX minicomputers use a format for floating-point numbers that is not the same as the IEEE standard. What is this format, and why was it chosen by the designer of the VAX computers? , A reference for VAX floating-point representation is Sebesta (1991).
= The existing DEC VAX formats, inherited from the PDP-11, because The PDP-11 had several uniquely innovative features, and was easier to program than its predecessors through the additional general-purpose registers.
4.Compare the tombstone and lock-and-key methods of avoiding dangling pointers, from the point of view of safety and implementation cost.
= Tombstones take more memory, while lock-&-key requires add’l cpu time on each ptr assignment to copy key as well as pointer. Pointer arithmetic could overwrite key in the heap.
5. What disadvantage are there in implicit dereferencing of pointers, but only in certain contexts? For example, consider the implicit dereference of a pointer to a record in Ada when it is used to reference a record field.
= When implicit dereferencing of pointers occurs only in certain contexts, it makes the language slightly less orthogonal. The context of the reference to the pointer determines its meaning. This detracts from the readability of the language and makes it slightly more difficult to learn.