Pages

Sunday 7 April 2013

Chapter 6


An assignment from Mr. Tri Djoko Wahyono (as always). As what the title said, it is the answer for some question (16 numbers, quite randomly in Review Qustion and 5 or maybe 6 numbers in Problem Set) in Chapter 3 in "Concept of Programming Language" book.


Review Question
1. What is a descriptor?
A descriptor is the collection of the attribute of a variable.

2. 
What are the advantages and disadvantages of decimal data types?
Decimal types have the advantages of being able to precisely store decimal values, at least those within a restricted range which cannot  be done with floating-point.
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?

4. Describe the three string length  options.
The first option, when the length can be static and set when the string is created, it is called a static length string.
The second option is to allow strings to have varying length up to a declared and fixed maximum set by the variable''s definition, which is called a limited dynamic length string.
The third option is to allow strings to have varying length with no maximum, which is called a dynamic length string.

5. Define ordinal, enumeration, and subrange types.

  • An ordinal type is one in which the range if possible values can be easily associated with the set of positive integers.
  • An enumeration type is one in which all of the possible values, which are named constants, are provided, or enumerated, in definition.
  • A subrange type is a contiguous subsequence of an ordinal type.

8. What are the design issues for arrays?

  • 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 multidimensioned arrays allowed, or both?
  • Can arrays be intialized when they have their storage allocated?
  • What kinds of slices are allowed, if any?

13. What languages support array slices with stepsizes?
Phyton, Perl, and Ruby.
21. What is the purpose of level numbers in COBOL records?
Level numbers indicate by their relative values the hierarchical structure of the record.

24. Are the tuples of Phyton mutable?
No, Phyton includes an immutable tuple type.

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?


43. What is a compatible type?
A compatible type is one that either as legal for the operator or is allowed under language rules to be implicitly converted by compiler-generated code (or the interpreter) to a legal type.


44. Define type error.
A type error is the application of an operator to an operand of an inappropriate type.


45. Define strongly typed?
Strongly typed is a type of language which type errors are always detected.


49. Why are C and C++ bot strongly typed?
C and C++ are not strongly typed languages because both include union types, which are not type checked.


52. What is the primary advantage of name type equivalence?
Name type equivalence is easy to implement.



53. What is the primary disadvantage of structure type equivalence?
Structure type equivalent is more difficult to implement.





Problem Set
2. How are negative integers stored in memory?
A negative integer could be stored in a bit that indicate that it is a negative number, but not lend itself to computer arithmetic.

7. Compare the pointer and reference type variable in C++.
In C++, pointers can be used in the same ways as addresses are used in assembly languages. it is similar to a reference type, with one important and fundamental difference: A pointer refers to an object or a value in memory.

19. Any type defined with typedef is type equivalent to its parent type. How does the use of typedef differ in C and C++?
Any type defines with typedef is type equivalent to its parent type. One exception to C using name type equivalence for structures, enumeration, and files, in which case structural type equivalence is used. C++ is like C except there is no exception for structures and unions defined in different files.

21. In what way is dynamic type checking better than static type checking?
It is better to detect errors at compile time than at run time, because the earlier correction is usually less costly. The penalty for static checking is reduced programmer flexibility. Fewer shortcut and tricks are possible.

22. Explain how the dangling-pointer problem can be removed using the locks-and-keys approach.
The best solution to the dangling-pointer problem is to take deallocation of heap-dynamic variables out of the hands of programmers. If programs cannot explicitly deallocate heap-dynamic variables, there will be no dangling-pointers.

No comments:

Post a Comment