Chapter 6-Concepts of Programming Languages(Robert W. Sebesta)-Mr. Tri Djoko Wahjono, Ir, M.Sc.

REVIEW QUESTION

1. What is a descriptor?

A descriptor is the collection of the attributes of a variable.

 

2. What are the advantages and the disadvantages of decimal data types

Decimal types have the advantage of being able to precisely store decimal values, at least those within a restricted range, which cannot be done with floating-point. For example, the number 0.1 (in decimal) can be exactly represented in a decimal type, but not in a floating-point type. The disadvantages of decimal 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 design issues for character string types?

-Should strings be simply a special kind of character array or a primitive type?

-Should strings have static or dynamic length?

 

8. What are the design issues for array?

-What types are legal for subscripts?

-Are subscripting expressions in element references range checked?

-When are subscript ranges bound?

-When does array allocation take place?

-Are ragged or rectangular multi-dimensioned arrays allowed, or both?

-Can arrays be initialized when they have their storage allocated?

-What kinds of slices are allowed, if any?

 

17. Define row major order and column major order

Row major order is where the elements of the array that have as their first subscript the lower bound value of that subscript are stored first, followed by the elements of the second value of the first subscript, and so forth. If the array is a matrix, it is stored by rows. Column major order is where the elements of an array that have as their last subscript the lower bound value of that subscript are stored first, followed by the elements of the second value of the last subscript, and so forth. If the array is a matrix, it is stored by columns.

 

22. Define fully qualified and elliptical references to fields in records.

A fully qualified reference to a record field is one in which all intermediate record names, from the largest enclosing record to the specific field, are named in the reference. Both the COBOL and the Ada example field references above are fully qualified. In an elliptical reference, the field is named, but any or all of the enclosing record names can be omitted, as long as the resulting reference is unambiguous in the referencing environment.

 

24. Are the tuple of Phyton mutable?

Python includes an immutable tuple type. If a tuple needs to be changed, it can be converted to an array with the list function. After the change, it can be converted back to a tuple with the tuple function.

 

32. What are the design issues for union?

-Should type checking be required? Note that any such type checking must be dynamic.

-Should unions be embedded in records?

 

35. What are the design issues for pointer types?

What are the scope and lifetime of a pointer variable?

-What is the lifetime of a heap-dynamic variable (the value a pointer references)?

-Are pointers restricted as to the type of value to which they can point?

-Are pointers used for dynamic storage management, indirect addressing, or both?

-Should the language support pointer types, reference types, or both?

 

36. What are the two common problems with pointers?

Dangling pointer, dangling pointer, or dangling reference, is a pointer that contains the address of a heap-dynamic variable that has been deallocated. Dangling pointers are dangerous for several reasons. First, the location being pointed to may have been reallocated to some new heap-dynamic variable. Furthermore, if the dangling pointer is used to change the heap-dynamic variable, the value of the new heap-dynamic variable will be destroyed. Finally, it is possible that the location now is being temporarily used by the storage management system, possibly as a pointer in a chain of available blocks of storage, thereby allowing a change to the location to cause the storage manager to fail.

Lost heap-dynamic, a lost heap-dynamic variable is an allocated heap-dynamic variable that is no longer accessible to the user program. Such variables are often called garbage, because they are not useful for their original purpose, and they also cannot be reallocated for some new use in the program.

 

44. Define type error

A type error is the application of an operator to an operand of an inappropriate type. For example, in the original version of C, if an int value was passed to a function that expected a float value, a type error would occur (because compilers for that language did not check the types of parameters).

 

44. Define strongly typed

A strongly typed is if type errors in a programming language are always detected.

 

45. Describe the three string length options

Static length string: the length can be static and set when the string is created.

Limited dynamic length string: allow strings to have varying length up to a declared and fixed maximum set by the variable’s definition, as exemplified by the strings in C and the C-style strings of C++.

Dynamic length strings: allow strings to have varying length with no maximum, as in JavaScript, Perl, and the standard C++ library.

 

50. What is name type equivalence?

Name type equivalence means that two variables have equivalent types if they are defined either in the same declaration or in declarations that use the same type name.

 

51. What is structure type equivalence?

Structure type equivalence means that two variables have equivalent types if their types have identical structures.

 

PROBLEM SET

2. How are negative integers stored in memory?

A negative integer could be stored in sign-magnitude notation, in which the sign bit is set to indicate negative and the remainder of the bit string represents the absolute value of the number. Sign-magnitude notation, however, does not lend itself to computer arithmetic. Most computers now use a notation called twos complement to store negative integers, which is convenient for addition and subtraction.

 

5. What disadvantages 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 de-referencing 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.

 

6. Compare the use of Boolean data types in C++ and Java. Give emphasis on their use in conditional statements and conditional loops.

The use of boolean in C++ and Java is almost the same. Boolean is a variable which has only 2 values : true and false. The only difference would be the primitive in C++ is bool while Java uses Boolean. On their use of conditional statements, they determine whether a loop or conditional statement is executed. The difference is that Boolean in Java does not accept integers as true / false value. They only accept the value either “true” or “false”. While in C++, it is possible to assign 1 as the value of a boolean which means true and 0 as false.

 

9. C provides twi derived data types both for name and structure type equivance: struct and union. Make a study on when to use struct type variables and union type variable.

If all data members of the variables are to be used at once then struct type variables are required, otherwise union type variables should be used.

 

11. In the Burroughs Extended ALGOL language, matrixes are stored as a single-dimensioned array of pointers to the rows of the matrix, which are treated as single-dimensioned arrays of values. What are the advantages and disadvantages of such a scheme?

The advantage of this scheme is that accesses that are done in order of the rows can be made very fast; once the pointer to a row is gotten, all of the elements of the row can be fetched very quickly. If, however, the elements of a matrix must be accessed in column order, these accesses will be much slower; every access requires the fetch of a row pointer and an address computation from there. Note that this access technique was devised to allow multidimensional array rows to be segments in a virtual storage management technique. Using this method, multidimensional arrays could be stored and manipulated that are much larger than the physical memory of the computer

 

21. In what way is dynamic type checking is better than static type checking?

It is better to detect errors at compile time than at the run time, because the earlier correction is usually less costly.

Leave a comment