[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP Pascal for OpenVMS
Language Reference Manual


Previous Contents Index


Chapter 8
Predeclared Functions and Procedures

HP Pascal supplies predeclared procedures and functions that perform various commonly used operations. You do not have to declare these routines in order to call them from your code.

In this chapter, the routines are presented in alphabetical order. To save you the time of scrolling through all the routines, you may wish to click on the Table Of Contents entry for the desired routine.

Also in this chapter, the term arithmetic types refers to those data types you can use in arithmetic operations: the integer, unsigned, and real types.

In some sections of this manual, reference is made to entire categories of routines. Table 8-1 lists the routines in each category.

Table 8-1 Predeclared Routine Categories
Category Category Description and Routines
Allocation size Routines that provide information about the amount of storage allocated for variables and for components of various types: BITNEXT, BITSIZE, NEXT, and SIZE
Arithmetic Routines that perform mathematical computations: ABS, ARCTAN, CARD, COS, EXP, EXPO, LN, LSHIFT, RSHIFT, MAX, MIN, RANDOM, SEED, SIN, SQR, SQRT, UNDEFINED, UAND, UNOT, UOR, UXOR, and XOR
Character-string Routines that manipulate character strings: BIN, DEC, FIND_MEMBER, FIND_NONMEMBER, HEX, INDEX, LE, LENGTH, LT, NE, OCT, PAD, READV, STATUSV, UDEC, and WRITEV
Component position Routines that provide information about the offset of record components: BIT_OFFSET and BYTE_OFFSET
Condition handling ASSERT, ESTABLISH, REVERT
Date-time Routines that provide information on the calendar date and time: CLOCK, SYSCLOCK, TIME, and WALLCLOCK
Dynamic allocation Routines that provide for the creation and use of pointer variables: ADDRESS, DISPOSE, IADDRESS, IADDRESS64, and NEW
File operations Routines that create, rename, and remove files and directories: CREATE_DIRECTORY, DELETE_FILE, RENAME_FILE
Input and Output Routines that you use for I/O; these routines are not described in this chapter
Low-level Routines that allow for parallel processes and for asynchronous routines to operate in a real-time or multitasking environment: ADD_ATOMIC, AND_ATOMIC, ADD_INTERLOCKED, BARRIER, CLEAR_INTERLOCKED, OR_ATOMIC and SET_INTERLOCKED
Null-terminated strings Routines that operate on null-terminated strings: C_STR, MALLOC_C_STR, PAS_STRCPY, PAS_STR
Ordinal Routines that provide information on the ordered sequence of values: PRED, SUCC, LOWER and UPPER,
Parameter Routines that give information about parameter lists: ARGC, ARGV, ARGUMENT, ARGUMENT_LIST_LENGTH, and PRESENT
Privileged (OpenVMS VAX systems only) Routines that manipulate privileged hardware registers: MFPR and MTPR
Type conversion Routines that convert an actual parameter to data of another type: CHR, DBLE, INT, INT64, ORD, PACK, QUAD, ROUND, ROUND64, SNGL, TRUNC, TRUNC64, UINT, UINT64, UNPACK, UROUND, UROUND64, UTRUNC, and UTRUNC64
Miscellaneous FIND_FIRST_BIT_CLEAR, FIND_FIRST_BIT_SET, UNDEFINED, and ZERO

Note

Not all routines are supported on all operating system and machine architecture environments. If a routine is not supported on all environments, the routine description includes any limitations.

For More Information:

8.1 ABS Function

The ABS function returns a value (of the same data type as the specified parameter) that is the absolute value of the parameter.


ABS( x )

The parameter x can be of any arithmetic type.

8.2 ADD_ATOMIC Function (OpenVMS I64 and OpenVMS Alpha systems only)

The ADD_ATOMIC function adds the value of an expression to the value of a variable, stores the newly computed value in the variable, and returns the previous value of the variable.


ADD_ATOMIC( e, v )

The type of the expression e must be assignment compatible with that of the variable v. The variable v must be an INTEGER, UNSIGNED, INTEGER64, or UNSIGNED variable and must be allocated on a natural boundary, such as longword for INTEGER and UNSIGNED and quadword for INTEGER64 and UNSIGNED64. The result of ADD_ATOMIC is the same type as the variable v.

Overflow and subrange checking are never performed on the ADD_ATOMIC operation, even if these options are in effect for the rest of the function or compilation unit.

The ADD_ATOMIC function does not provide memory synchronization between multiple processors. The BARRIER predeclared routine must be used for that purpose.

This function is used to access data that is shared between two or more threads of execution.

For More Information

  • On atomic operations (HP Pascal for OpenVMS User Manual)

8.3 ADD_INTERLOCKED Function

The ADD_INTERLOCKED function adds the value of an expression to the value of a variable, stores the newly computed value in the variable, and returns an integer value: -1 if the new value is negative, 0 if it is zero, and 1 if it is positive.


ADD_INTERLOCKED( e, v )

The type of the expression e must be assignment compatible with that of the variable v. The variable v must be an integer or an unsigned subrange; v must have an allocation size of two bytes and must be aligned on a word boundary. The type of e must be assignment compatible with that of v.

Note that unless the type of v is an integer subrange that includes negative values, the result of the ADD_INTERLOCKED function is never -1.

Overflow and subrange checking are never performed on the ADD_INTERLOCKED operation, even if these options are in effect for the rest of the function or compilation unit.

This function is used to access data that is shared between two or more threads of execution.

For More Information

  • On atomic operations (HP Pascal for OpenVMS User Manual)

8.4 ADDRESS Function

The ADDRESS function returns a pointer value that is the address of the parameter.


ADDRESS( x )

The parameter x can be a variable of any type except a component of a packed structured type. A compile-time warning results if x is a formal VAR parameter, a component of a formal VAR parameter, or a variable that does not have the READONLY or VOLATILE attribute.

A pointer can only refer to a VOLATILE variable or a variable allocated by the NEW procedure.

For More Information:

8.5 AND_ATOMIC Function (OpenVMS I64 and OpenVMS Alpha systems only)

The AND_ATOMIC function logically ANDs the value of an expression to the value of a variable, stores the newly computed value in the variable, and returns the previous value of the variable.


AND_ATOMIC( e, v )

The type of the expression e must be assignment compatible with that of the variable v. The variable v must be an INTEGER, UNSIGNED, INTEGER64, or UNSIGNED64 variable and must be allocated on a natural boundary, such as longword for INTEGER and UNSIGNED and quadword for INTERGER64 and UNSIGNED64. The result of AND_ATOMIC is the same type as the variable v.

The AND_ATOMIC function does not provide memory synchronization between multiple processors. The BARRIER predeclared routine must be used for that purpose.

This function is used to access data that is shared between two or more threads of execution.

For More Information

  • On atomic operations (HP Pascal for OpenVMS User Manual)

8.6 ARCTAN Function

The ARCTAN function returns a real value that expresses in radians the arctangent of the specified parameter.


ARCTAN( x )

The parameter x can be an integer or REAL type.

8.7 ARGUMENT Function

The ARGUMENT function specifies an argument in a variable-length parameter list that was created using the LIST attribute.


ARGUMENT( parameter-name, n )

The parameter-name argument specifies the name of a parameter declared with the LIST attribute. The parameter n specifies a positive integer value that identifies the argument. The first argument in a list is always 1. An error occurs if the value supplied for n is less than 1, or exceeds the ARGUMENT_LIST_LENGTH parameter (which indicates the total number of arguments).

If the LIST parameter is a value parameter, ARGUMENT indicates the corresponding value in the argument list. If the LIST parameter is a VAR parameter, ARGUMENT is a reference to the corresponding variable in the argument list.

Also, you can use the IADDRESS function with the ARGUMENT function to return the address of a selected argument.

For More Information:

8.8 ARGUMENT_LIST_LENGTH Function

The ARGUMENT_LIST_LENGTH function returns an integer value representing the number of arguments in a variable-length parameter list that was created using the LIST attribute.


ARGUMENT_LIST_LENGTH( parameter-name )

The parameter-name argument specifies the name of the parameter declared with the LIST attribute.

When creating a variable-length parameter list, you can place the LIST attribute on only the last formal parameter. When you call the routine, you can specify any number of actual parameters, or arguments, that correspond to the last formal parameter declared with LIST. Consider the following example.



PROGRAM Show_Arg( OUTPUT );
                  {Ax corresponds to any number of char. arguments}
PROCEDURE Variable_Write( Fl : VARYING[len] OF CHAR;
                          Ax : [LIST] CHAR );
   VAR
      i : INTEGER;
   BEGIN
   WRITE( Fl, ', ' );
   {For however many arguments there are:}
   FOR i := 1 TO ARGUMENT_LIST_LENGTH( Ax ) DO
      WRITE( ARGUMENT( Ax, i ) );               {Write an argument}
   WRITELN;
   END;
{In the executable section:}
Variable_Write( ' hello', '*' );  {One argument: Writes ' hello, *'}
Variable_Write( ' hello','s','a','i','l','o','r','!' );
                      {Seven arguments: Writes ' hello, sailor!'}

For More Information:

8.9 ASSERT Procedure

The ASSERT procedure signals a run-time error if the value of its parameter is FALSE. ASSERT takes this form:


ASSERT(expression [[, string]])

The parameter expression is a Boolean expression that is normally true. If ASSERT evaluates the expression as false, it signals a run-time error indicating that the assertion failed.

The optional string parameter is output as part of the error message.

8.10 BARRIER Function (OpenVMS I64 and OpenVMS Alpha systems only)

The BARRIER procedure causes a memory barrier instruction to be emitted to synchronize pending memory updates in a multi-processor environment.


BARRIER

The BARRIER procedure has no parameters.

This routine is used to serialize memory writes on OpenVMS I64 and OpenVMS Alpha systems.

For More Information

  • On memory granularity (HP Pascal for OpenVMS User Manual)

8.11 BIN Function

The BIN function returns a character-string value that is the binary equivalent of the specified parameter. The return value is compatible with all other string types.


BIN( x[[, length[[, digits]] ]] )

The parameter x is the expression to be converted. This parameter must have a size that is known at compile time; it cannot be VARYING OF CHAR, a conformant parameter, or a schema type.

Two optional integer parameters specify the length of the resulting string and the minimum number of significant digits to be returned. If you specify a length that is too short to hold the converted value, the resulting string is truncated on the left.

If you omit the optional parameters, the bit width of the converted parameter value determines the string length and the number of significant digits. By default, the number of significant digits is the minimum number of characters necessary to express all the bits of the converted parameter. This default length is one character more than the default number of digits, which causes a leading blank to be included in the resulting string when both parameters are omitted. Consider the following example:



TYPE
   Month_Dates = SET OF 0..31;
VAR
   Days_Of_Rain :  Month_Dates;
{In the executable section:}
Days_Of_Rain := [1, 2, 6, 10, 12, 14, 18, 22, 25, 30];
Result := BIN (Days_Of_Rain, 32);
{Returns '01000010010001000101010001000110', 32 characters}

The binary representation is from right to left, with the leftmost bit being bit 31 and the rightmost bit being bit 0.

For More Information:

8.12 BIT_OFFSET Function

The BIT_OFFSET function returns an integer value that represents the bit position of a field in a record.


BIT_OFFSET( t, f )

The parameter t can be of any record type or variable, and the parameter f can be any field contained in that record.

For More Information:

On records ( Section 2.4.2)

8.13 BITNEXT Function

The BITNEXT function returns an integer value that indicates the number of bits that would be allocated for one component of the specified type in a packed array or if the specified variable appeared as a cell in a packed array.


BITNEXT( x )

The parameter x can be a variable or any type identifier.

Cells in a packed array are affected by any alignment attributes placed on them. Therefore, the size returned includes the actual size of the type or variable in addition to trailing space required to ensure proper alignment.

The BITNEXT and BITSIZE functions return the same bit size for a given type or variable, except where the components of the packed array are padded to ensure proper alignment.

For More Information:

8.14 BITSIZE Function

The BITSIZE function returns an integer value that indicates the number of bits that would be allocated for one field of the specified type in a packed record or if the specified variable appeared as a field in a packed record.


BITSIZE( x )

The parameter x can be a variable or any type identifier.

Fields in a packed record are not affected by any alignment attributes placed on subsequent fields. Therefore, the size returned indicates the actual size of the type or variable.

The BITNEXT and BITSIZE functions return the same bit size for a given type or variable, except where the components of the packed array are padded to ensure proper alignment.

For More Information:

8.15 BYTE_OFFSET Function

The BYTE_OFFSET function returns an integer value that represents the byte position of a field in a record.


BYTE_OFFSET( t, f )

The parameter t can be of any record type or variable, and the parameter f can be any field contained in that record.

For More Information:


Previous Next Contents Index