• Aucun résultat trouvé

Standard Procedures and Functions

Dans le document Language Pascal (Page 136-152)

This Chapter describes all the standard C'bullt-lnt, procedures and functions in Pascal on the Usa, except for the I/O procedUres and functions described in Chapter 10.

Standard procedUres and functions are predeclared. Since all predeclared entitles act as if they were declared 1n a block surrounding the program, no conflict arises from a declaration that redefines the same identifier within the program.

Standard procedUres and functions cannot be used as actual procedural and functional parameters.

This chapter uses a modified BNF notation, instead of syntax diagrams, to indicate the syntax of actual-parameter-Usts for standard procedures and functions. The notation Is explained at the beginnIng of Chapter 10.

11.1 Exit cnj Halt ProceWres 11.1.1 The Exit ProcEUJre

Exits immediately from a specified procedure or function, or from the main program.

Parameter List: exlt(ld)

1. Id Is the Identifier of a procedure or function, or of the main program. If Id Is an identifier defined In the program, it must be in the scope of the

exit call. Note that this is more restricted than UCSD Pascal.

Exlt(1d) causes an ImmedIate exit from 1(1 Essentially, it causes a jump to the

end of Id.

The halt procedure (see below) can be used to exit the main program from a U1lt without knowing the maln programts identifier.

11.1.2 The Halt ProcEUJre

Exits immediately from the main program.

Pa.lCll77eter List- no parameters

Halt causes an immediate exit from the main program.

11.2 Dynamic Allocatioo P:rocedUres

These procedures are used to manage the heap, a memory area that is unallocated when the program starts running. The procedure new is used for

11-1

PascaJ Reference Ma7tl8J St8l1d8Jr1 P.rocedtIres & FU7CtJons record-type with variants (see below~

Ne\v(p) allocates a new variable of the base-type of p, and makes p point to it.

P8SC8l Refe.rence /VIanua1 Standard ProcedJres & FlIlCtions

112.2 The ~result FlIlCtlon

Returns the status of the most recent dynamic allocation operation.

Result Type: integer

Parameter LIst: no parameters

Heapresult returns an integer code that reflects the status of the most recent

11.2.4 The Release ProcetiJre

Deallocates all variables in a marked heap area

1125 The 1VIemavai1 FlIlCtlon

Returns the maximum possible amount of available memory.

Result Type: looglnt

Parameter List: no parameters

Memavall returns the maximum number of words (not bytes) of heap and stack

Pascal Refe.rence M8I7I.I8l St8l1d8rd Procedllres & Fvnctlons

Pascal Reference H8niJ8J Stend8rd ProcedlIres & Functions

This expressIon causes 32-bit arIthmetic to De used, and the result is a 32-bit longint value.

If x is of an ordinal-type other than integer or looglnt, the numerical value of the result Is the ordinal number determined by mapping the values of the type onto consecutive non-negative integers starting at zero.

11.3.4 The Pointer FU'lCtion

Converts an integer or longint value to pointer-type.

ReSlllt 7)pe: pointer Paratneter List: pointer(x)

1. x is an expression with a value of type Integer or longlnt.

Polnter(x) returns a pointer value that corresponds to the physical address x.

This pointer is of the same type as nil and is assignment-compatible with any pointer-type.

11.4 Arlt.tmet1c FU'lCtlons

In general, any real result returned by an arithmetic fUnCtion is an approx-imation. There are t'Wo exceptions to this: the result of the abs function Is exact, and the result of the pwroften function is exact when the parameter n is in the range 0 ~ n ~ 10.

11.4..1 The ( w FU'lCtlon

Tests whether a 'Whole-number value is odd.

ReSlJJt 7)pe: bOOlem Parameter List: odd(x)

1. x is an expression 'With a value of type Integer or longlnt.

~x) returns true if x is odd; other'Wise it yIelds false.

11.4.2 The NJs FU'lCtion

Returns the absolute value of a numeric value.

Result 7ype: same as parameter Parameter List: cms(x)

1. x Is an expressIon with a value of type real, Integer, or longlnl Ab(x) returns the absolute value of x.

11-5

P8SC8l ReFemnce fv18nI.I81

Pasc8l RefeImCe Manu8l St8lld8rd PJVCedlIres & Functions

11.4.7 The Ln FlIlCtion

Returns the natural logarIthm of a numeric value.

ReSUlt Type: real Parameter List: In(x)

1. x Is an expression wIth a value of type real, Integer, or longlnt All non-negative values are valid; negative values are Invalid.

If x Is non-negative, lr(x) returns the natural logarithm (loge) of x.

If x is negative, a diagnostic NaN Is produced and the Invalid qleraUon signal Is set (see Appendix D~

11.4.8 The Sqrt FlIlCtion

Returns the square root of a numeric value.

Result Type: real Parameter List: sqrt(x)

1. x Is an expression with a value of type real, integer, or longlnt All non-negative values are valid; negative values are inval1d.

If x is non-negative, sqrt(x) returns the positive square root of x.

If x is negative, a diagnostic NaN is produced and the Invalid qleratlon signal is set (see AppendIx D~

11.4.9 The Arctan FlIlCtion

Returns the arctangent of a numeric value.

ReSUlt Type: real

Parameter List: arctal(x)

1. x Is an expression with a value of type real, integer, or longlnt All numeric values are valid, including :too.

Arctar(x) returns the prInclpal value, in radlans, of the arctangent of x.

11.4.10 The Pwroften FlIlCtion

Returns a spec1 fied power of 10.

ReSUlt Type: real

Parameter List: pfi'Often(n)

1. n is an expression with a value of type Integer.

If -45 ~ n ~ 38, then pwrofter(n) returns 1

on.

The result is mathematically exact for 0 ~ n ~ 10. If n ~ -46, the result is 0; if n ~ 39, the result is +00.

11-7

Pascal RefellJl7Ce H817t18l Standa.ld Procedures & Fl/I?CtJons

Returns the Char value corresponding to a whole-number value.

Result Type: char (but see below)

Pascal Reference /VIant/al Stand8.rd P.rocett.ues & FlIJCtions

If x is the last value in the type of x., it has no successor. In this case the value returned is not within the range of the type of x., and any attempt to

assign it to a variable of this type will cause unspecified results.

11.5.4 The Pled Ft.rlCtlon

Returns the predecessor of a value of ordinal-type.

Result

TYPe:

same as parameter (bUt see below) PaJ1ilIT1eter List: pred(x)

1. x is an expression with a value of ordinal-type.

Pret:(x) returns the predecessor of x., if such a value exists aCCOrding to the inherent ordering of values in the type of x.

If x is the first value In the type of X, it has no predecessor. In this case the value returned is not within the range of the type of x., and any attempt to assign it to a variable of this type will cause unspecified results.

11.6 StriBJ ProceclJreS CI1d Ft.rlCtions

The string procedures and functions do not accept packed array Of Char

parameters, and they do not. accept indexed string parameters.

11.6.1 The Length FlJ'lCtlon

Returns the current length of a value of string-type.

Result 7jpe: integer Parameter List: lengtt(str)

1. str is an expression with a value of string-type.

Lengtt(str) returns the current length of str.

1L62 The Pes Ft.rlCtion

Searches a string for the first occurrence of a specified SUbstring.

Result TYpe: integer

PSJ1!JI718ter List: pos(Sltlstr, str)

1. SUbStr is an expressIon wIth a value of string-type.

2. str is an expression with a value of strIng-type.

Pos(SUbStr, str) searches for SUbStr within str, and returns an integer value that is the index of the first character of SUbStr wi thin str.

If SUbStr is not found, pos(Sltlstr, str) returns zero.

11-9

P8SC8I ReFerence I'18ntI8J

Returns a Substring of specIfIed length, taken from a specified posItion within a string.

Result Type: string-type

Parameter List: copy{ source, index, COU'lt)

1. source is an expression with a value of string-type.

2. Index Is an expression with an Integer value.

3. COlIlt Is an expressIon with an Integer value.

COpy(srurce, Index, COUlt) returns a strIng conta1ning COUlt characters from srurce, beginning at source[lndexJ

11.65 The Delete ProceOJre

Deletes a sUbstring of specified length from a specified positlon within the value of a string variable.

Parameter List: delete( dest, index, COU'lt)

1. dest is a variable-reference that refers to a variable of strIng-type. This is a variable parameter.

2. Index Is an expression wIth an Integer value.

3. CCUlt is an expression with an Integer value.

Delete(dest, index, COl.I1t) removes COUlt characters from the value of dest"

beginning at dest[lndexJ 11.6.6 The Insert ProceWre

Inserts a substring into the value of a string variable, at a specified position.

Pascal Reference Hanl/al Standard Procedures & Functions

Insert(source, den, Index) inserts source into dest. The first character of source becomes deSt{index}

11.7 Byte-Orlented Procedures and FtflCtioos

These features allow a program to treat a program variable as a sequence of

11.7.1 The Moveleft PIOCe(lJre

Copies a specified number of contiguous bytes from a SOl/rce range to a

destination range (starting at the lowest address~

Paratneter List- nove1eft(source, dest, COU'lt)

1. source is a variable-reference that refers to a variable of any type variable parameter. The first byte allocated to dest (lowest address within dest) is the first byte of the destination range.

Pascal ReFerence Mantia} Standard Procedtlres & Functions

Moveleft starts from the "left" end of the source range (lowest address~ It proceeds to the "right" (higher addresses), copying bytes into the destination range, starting at the lowest address of the destlnation range.

11.8.1 llle SCCI1eq FlIlCtion

Searches a packed array Of char for the first occurrence of a specified character.

Result Type: Integer

Parameter List.; sccmq(limit, Ch, paoc)

1. llmlt is an expression with a value of type Integer or longint It is truncated to 16 bits, and is not range-checked.

2. Ch is an expression with a value of type char.

11-12

Pascal ReFerence /t1anuaJ StandaJ11 Pnx:et1Ures & FUlCtions 3. pace is an expression with a value of type packed array Of char. This is

a variable parameter.

scaneqIlmlt, Ch, pace) scans pace, looking for the first occurrence of Ch. The scan begins with the first character In paoo. If the character Is not found within limit characters from the beginning of pace, the value returned is equal to limit Otherwise, the value returned is the number of characters scanned before ch was found.

11.8.2 TIle SCcn1e FtrlCtloo

This function is exactly like scaleq, except that it searches for a character that does not match the 00 parameter.

11.8.3 The FlllChar Procecl.Ire

Fills a specified number of characters In a packed array Of char with a specified Character.

P8I'l1IT1eter List: fl11char(paoc, C€Ult, 00)

1. pace is an expression with a value of type pooked array Of char. This is a variable parameter.

2. COl.flt is an expresSion with a value of type Integer or longlnt It is truncated to 16 bits, and is not range-checked.

3. ch Is an expression with a value of type char.

FlllchaI(paoc, COU1t, 00) writes the value of 00 into COtIlt contiguous bytes of memory, starting at the first byte of paoc.

Since the cot.rlt parameter is not range-checked, it Is possIble to write into memory outside of pace, with unspecified results.

11-13

029-0404-A

Chapter 12 The Compiler

12.1 COIll>11er COfTVTlands ... 12-1 12.2 conct1tional CClrr1Jilation ... 12-3 12.2.1 CompIle-TIme VarIables and the IDECL Command •••.•••••...•...•.. 12-3 12.2.2 The $SETC Command ... 12-4 12.2.3 CompIle-TIme Expressions ... 12-4 12.2.4 The $IFC, $ELSEC, and $ENDC Commands ... 12-4 12.3 ~tlmlzation of If-Statements . 0 • • • • • • • • • 0 • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • 0 . 12-5 12.4 ~tlmlzat1on Of While-Statements CIld Repeat-Statements ... 12-7 12.5 EffIcIency Of case-staterTlents ... 12-7

Dans le document Language Pascal (Page 136-152)

Documents relatifs