Java Reference
In-Depth Information
9. Assume that in Cwe have the declaration int a[5][10][20],wherea is
allocated at address 1000. What is the address of a[i][j][k] assuming
a is allocated in row-major order? What is the address of a[i][j][k]
assuming a is allocated in column-major order?
10. Most programming languages (including Pascal, Ada, C, and C
)al-
locate global aggregates (records, arrays, structs, and classes) statically,
while local aggregates are allocated within a frame. Java, on the other
hand, allocates all aggregates in the heap. Access to them is via object
references allocated statically or within a frame. Is it less e
++
cient to ac-
cess an aggregate in Java because of its mandatory heap allocation? Are
there any advantages to forcing all aggregates to be uniformly allocated
in the heap?
11. In Java, subscript validity checking is mandatory. Explain what changes
would be needed in C or C
(your choice) to implement subscript
validity checking. Be sure to address the fact that pointers are routinely
used to access array elements. Thus you should be able to checks array
accesses that are done through pointers, including pointers that have
been incremented or decremented.
++
12. Assume we add a new option to C
arrays that are heap-allocated, the
flex option . A flex array is automatically expanded in size if an index
beyond the array's current upper limit is accessed. Thus we might see:
++
ar = new flex int[10]; ar[20] = 10;
The assignment to position 20 in ar forces an expansion of ar's heap
allocation. Explain what changes would be needed in array accessing to
implement flex arrays. What should happen if an array position beyond
an array's current upper limit is read rather than written?
13. Fortran library subprograms are often called from other programming
languages. Fortran assumes that multidimensional arrays are stored
in column-major order; most other languages assume row-major order.
What must be done if a C program (which uses row-major order) passes a
multidimensional array to a Fortran subprogram. What if a Javamethod,
which storesmultidimensional arrays as arrays of array object references,
passes such an array to a Fortran subprogram?
 
Search WWH ::




Custom Search