18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6. Advanced Topics<br />

6.1 Introduction<br />

This chapter describes a variety of <strong>SIMSCRIPT</strong> <strong>II.5</strong> features which need not concern the first-time<br />

user, but which an experienced programmer may find of interest.<br />

6.2 Programmer-Defined Array Structures: Pointer Variables<br />

We stated previously that the allocation of storage space to an array is determined from the number<br />

of elements, or in the case of multidimensional arrays, from the product of the array dimension<br />

bounds. Although true in principle, this statement is a simplification. The storage allocation for the<br />

elements of a one-dimensional array, for example, is determined from both the number of elements<br />

and the declared mode of the array. Associated with this storage allocation is an array base pointer,<br />

which holds the address in the computer memory of the allocated storage space. In the case of a<br />

one-dimensional array named X, the associated base pointer is named X(*). Recall this usage in<br />

the reserve statement. The function of the reserve statement is to allocate computer storage to<br />

an array and assign the internal location of this storage as the value of the base pointer. An array<br />

base pointer is internally represented in a way similar to an integer variable. It can be manipulated<br />

as an integer variable. However, this is generally unnecessary and should be done with great<br />

care and full appreciation of the internal array representation.<br />

A one-dimensional array X, allocated storage by the statement:<br />

reserve X(*) as 10<br />

is structured as a contiguous group of memory locations, pointed to by the array base pointer, as<br />

shown in figure 6-1. The base pointer itself is not contiguous with the array storage, but is allocated<br />

storage in the same way as an integer variable.<br />

A two-dimensional array was introduced conceptually as an array of one-dimensional arrays. In<br />

fact, this is precisely how a two-dimensional array is internally represented. The base pointer of a<br />

two-dimensional array points not directly to the doubly subscripted variable elements, but to a onedimensional<br />

array of pointers. Each element of this pointer array serves as a base pointer for the<br />

one-dimensional array representing an entire row of the two-dimensional array. Note that the base<br />

pointer itself and the array of row pointers are all pointer type variables, and therefore stored in an<br />

integer-like form. The representation of the fully subscripted variable elements depends on the<br />

declared mode of the array. A two-dimensional array X, which has been allocated storage by the<br />

statement:<br />

reserve X(*,*) as 5 by 3<br />

is stored as shown in figure 6-2.<br />

249

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!