13.07.2015 Views

apple-pascal-1.3-manual

apple-pascal-1.3-manual

apple-pascal-1.3-manual

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.

The following rules govern the formation of array types and variables:o The elements of an array can be any type except a file type; inparticular, they can be arrays or records.o An array can have any number of dimensions.o The index scalars in an array may have from 1 to 32767 (MAXINT)values on each dimension. Thus they may be type CHAR or BOOLEAN orany subrange of CHAR. They may be a subrange of INTEGER up to thatlimit.o Scalars indexing different dimensions may be of different types.o Index scalar ranges may begin and end at any values, including negativeintegers. However, the end index must always have higher ordinalitythan the beginning index.o To access an array element, you may specify its index by using anyexpression that returns a scalar value within the index range. Suchexpressions include variables, constants, complex calculations, and arrayelements themselves. Expressions are defined in "Data Expressions" inChapter 6.o In array declarations, only constants may be used to specify arrayindices.Caution: It is easy to specify array variables that are too large to fit intothe available memory space when your program is run. Doing so will notcause a Compiler error. It is up to you to forestall this happening; forhelpful hints, see "Executing Large Programs" in Chapter 15.Multidimensional arrays are the same as arrays having otherarrays for their elements. Thus, for example, declaringARRAY[Iii •• 7, Ill .. 31 OF BOOLEANis exactly the same as declaringARRAY[0 .. 7l OF ARRAY [0 .. 31 OF BOOLEANThese two ways of declaring the same array are interchangeable whenarrays are not packed. With packed arrays, however, they have differenteffects. See below, "Multidimensional Packed Arrays."To illustrate some Pascal arrays, let us assume we are writing a program tohandle job costing data. We make the following scalar type declarations:TYPE DAY_WEEK=CMO,TU,WE,TH,FR,SA,SU);EMP_NUM=1 .. 21!i;JOB_NUM=1 .. 99;PAY_RATE•'A' .. 'KJ;{user-defined scalar}{integer subrange}{integer subrange}{CHAR subrange}III-44Chapter 4: Structured Data Types

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

Saved successfully!

Ooh no, something went wrong!