[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP Pascal for OpenVMS
|
Previous | Contents | Index |
HP Pascal in cooperation with the OpenVMS Linker performs compile-time and link-time checks to ensure that all compilations that inherit environment files actually used the same environment file definition. Information is placed in the object file such that the OpenVMS Linker will perform the same check between each object file that inherited environment files.
By default, compilation units that inherit an environment file compare the embedded compilation time inside the environment file against uses found in any other environment files that are also inherited. If the times are different, a compile-time message is displayed. This happens on all systems.
This checking can be disabled or modified by using the PEN_CHECKING_STYLE attribute in the Pascal source file that created the environment file. Once the environment file exists, its selected checking style will be performed at each use.
The PEN_CHECKING_STYLE attribute is valid at the beginning of a MODULE that creates an environment. The syntax is:
PEN_CHECKING_STYLE(keyword) |
In this syntax, keyword is:
The POS attribute forces the field to a specific bit position within the record.
POS( n ) |
The constant expression n specifies the bit location, relative to the
beginning of the record, at which the field begins.
n
Usage and Default Information:
Consider the following example:
TYPE Control = RECORD Flag_1 : [ BIT, POS( 0 ) ] BOOLEAN; Flag_2 : [ BIT, POS( 1 ) ] BOOLEAN; Count : [ BYTE, ALIGNED ] 0..100; Error : [ BIT, POS( 31 ) ] BOOLEAN; END; |
This example uses the POS attribute to position the fields of an unpacked record such that Flag_1 occupies bit 0, Flag_2 occupies bit 1, and Error occupies bit 31. Because the Count field has size and alignment attributes, it is allocated one byte of storage and is aligned on the byte boundary following Flag_2; that is, storage for Count occupies bits 8 through 15. Bits 2 through 7 and 16 through 30 are left empty; you cannot refer to them.
The PSECT attribute is useful for placing static variables and executable blocks in program sections that are shared among executable images.
[ PSECT [[ ( { identifier } ) ]] ] |
Identifier passed designating the program section in which storage for a variable, routine, or compilation is to be allocated. If you omit the identifier, the name of the variable is used as the name of the program section.identifier
Usage and Default Information:
The QUAD attribute specifies the amount of storage in quadwords to be received by the object.
QUAD [[( n )]] |
The optional constant n indicates the number of quadword storage units.
The READONLY attribute specifies that an object can be read by a program but it cannot have values assigned to it.
Usage and Default Information:
Consider the following example:
TYPE t = RECORD i : INTEGER; END; P_Read_Only = ^ [READONLY] t; VAR Pro : P_Read_Only; Prw : ^ T; PROCEDURE q( p : P_Read_Only); VAR x : INTEGER; BEGIN x := p^.i; {More statements...} END; {In the executable section:} NEW( Pro ): NEW( Prw ); Q( Pro ); Q( Prw ); Prw^.I := 0; |
This example shows the declaration of two pointer variables, Pro and Prw, and the calls to NEW that create the dynamic variables Pro^ and Prw^. The type of the formal parameter p requires that a corresponding actual parameter have read access; therefore, both Pro and Prw can legally be passed to Q as actual parameters. Because P is a READONLY parameter, the value of the dynamic variable P^ (which corresponds to either Pro^ or Prw^) can be assigned to a variable, as shown in the assignment statement in the body of Q. However, only Prw^ can have values assigned to it, as shown in the last statement.
The REFERENCE attribute causes the formal parameter value in a routine to be passed by reference using foreign semantics.
Usage and Default Information:
Consider the following example:
PROCEDURE Test1( P1 : [REFERENCE] INTEGER; P2 : [IMMEDIATE] INTEGER ); EXTERNAL; |
This example defines a procedure, Test1, which has two parameters. The first parameter, P1, is passed by reference. The second parameter, P2, is passed by immediate value.
The STATIC attribute causes HP Pascal to create a static object, which is allocated only once and exists as long as the executable image in which it is allocated remains active.
Usage and Default Information:
Consider the following example:
PROGRAM Print_Random( OUTPUT ); VAR i : [AUTOMATIC] INTEGER; FUNCTION Random : INTEGER; VAR x : [STATIC] INTEGER VALUE 15; BEGIN x := (( 9 * x ) + 7 ) MOD 11; Random := x; END; {In the executable section:} FOR i := 1 TO 20 DO WRITELN( Random ); END. |
The program Print_Random includes a function that generates a random integer. Because the variable x is declared STATIC, its value is preserved from one activation of the function to the next. By default, the storage for x would have been deallocated when control returned to the main program. Because x is static, it retains the value it had when Random ended and assumes this value the next time Random is called. In the program Print_Random, the program-level variable i is declared AUTOMATIC.
The TRUNCATE attribute indicates that an actual parameter list for a routine can be truncated at the point that the attribute was specified. You can use TRUNCATE with the PRESENT function.
Usage and Default Information:
The examples in this list are based on this PROCEDURE declaration from
Example 10-1, which shows the use of the TRUNCATE attribute with
default values:
PROCEDURE p( a : [TRUNCATE] CHAR := 'a'; b : CHAR := 'b'; c : [TRUNCATE] CHAR := 'c'; d : CHAR := 'd' ); |
p(); { DEFAULT a AND b--TRUNCATE AT c "ab" } |
p(,,); { DEFAULT a, b, c AND d "abcd" } |
p( c := y ); { DEFAULT a, b AND d "abyd" } |
In Example 10-1, each call to procedure p in the main body of the program has a comment that shows the expected parameter list behavior and the expected output. The parameter list is truncated at either parameter a or parameter c.
If parameters b and d did not have default values, the call p( w ) or p( w, x, y ) would be illegal because the list cannot be truncated at the second or fourth positions.
Example 10-1 Using the TRUNCATE Attribute |
---|
PROGRAM Trunc( OUTPUT ); VAR w : CHAR VALUE 'w'; x : CHAR VALUE 'x'; y : CHAR VALUE 'y'; z : CHAR VALUE 'z'; PROCEDURE p( a : [TRUNCATE] CHAR := 'a'; b : CHAR := 'b'; c : [TRUNCATE] CHAR := 'c'; d : CHAR := 'd' ); BEGIN IF PRESENT( a ) THEN WRITE( a ); IF PRESENT( b ) THEN WRITE( b ); IF PRESENT( c ) THEN WRITE( c ); IF PRESENT( d ) THEN WRITE( d ); WRITELN; END; {In the executable section:} { CALL LIST RESULT } p; { NO PARAMETERS--TRUNCATE AT a "" } p(); { DEFAULT a AND b--TRUNCATE AT c "ab" } p(,); { DEFAULT a AND b--TRUNCATE AT c "ab" } p(,,); { DEFAULT a, b, c AND d "abcd" } p(,,,); { DEFAULT a, b, c AND d "abcd" } p( w ); { DEFAULT b--TRUNCATE AT c "wb" } p( w, x ); { TRUNCATE AT c "wx" } p( w, x, y ); { DEFAULT d "wxyd" } p( w, x, y, z ); { NO DEFAULTS "wxyz" } p( a := w ); { DEFAULT b--TRUNCATE AT c "wb" } p( b := x ); { DEFAULT a--TRUNCATE AT c "ax" } p( c := y ); { DEFAULT a, b AND d "abyd" } p( d := z ); { DEFAULT a, b AND c "abcz" } |
The UNALIGNED attribute specifies that an object can be aligned on any
bit boundary.
10.2.38 UNALIGNED
Usage and Default Information:
The UNBOUND attribute specifies that a routine does not access automatic variables outside the scope in which it is declared. That is, the bound procedure value of an unbound routine does not include the static scope pointer.
Usage and Default Information:
Consider the following example:
[EXTERNAL] FUNCTION f( [IMMEDIATE, UNBOUND] PROCEDURE Count ) : BOOLEAN; EXTERNAL; PROCEDURE a; VAR i : [STATIC] INTEGER; b : BOOLEAN; [UNBOUND] PROCEDURE p; BEGIN i := i + 1; {Additional statements...} END; b := f( p ); END; |
This example shows the declaration of the unbound procedure p and the unbound formal procedure parameter Count. The executable section of p cannot access variables declared in the enclosing block of procedure a unless those variables are statically allocated. Procedure p can access the variable i, which is declared with the STATIC attribute, but it cannot access the variable b that is automatically allocated. Because the formal parameter Count is unbound, only other unbound routines (such as p) can be passed to function f as actual parameters. Count must be declared UNBOUND because it is passed by immediate value.
The UNSAFE attribute indicates that an object can accept values of any type without type checking. The exact properties of an unsafe object depend on the object's machine representation.
Usage and Default Information:
v : [LONG, UNSAFE] ( aa, bb, cc ); |
Consider the following example:
PROGRAM Output_Buffer( Data_File ); TYPE Natural = 0..MAXINT; VAR Data_File : FILE OF ARRAY[0..511] OF CHAR; Int_Array : ARRAY[0..1023] OF INTEGER; A_String : VARYING[2048] OF CHAR; Chr_Array : ARRAY[0..4095] OF CHAR; Status : BOOLEAN; FUNCTION Put_Buf( VAR Buffer : [UNSAFE] ARRAY[ a..b : Natural ] OF CHAR ) : BOOLEAN; VAR Cur : [STATIC] INTEGER VALUE 0; i : INTEGER; BEGIN FOR i := a TO b DO BEGIN Data_File^[Cur] := Buffer[i]; Cur := Cur + 1; IF Cur > 511 THEN BEGIN PUT( Data_File); Cur := 0; END; END; Put_Buf := (Cur = 0); END; {In the executable section:} Status := Put_Buf( Int_Array ); Status := Put_Buf( A_String ); Status := Put_Buf( Chr_Array ); |
The function Put_Buf assigns successive components of the conformant array parameter to the file buffer variable of Data_File. If Data_File^ is filled, the function returns TRUE; otherwise, it returns FALSE.
The program issues three calls to Put_Buf. In the first and second calls, the actual parameters are not of the same type as the formal parameter Buffer. However, because Buffer has the UNSAFE attribute, it accepts an actual parameter of any type and treats it as though it were an array of characters. The third call to Put_Buf passes an actual parameter of the same type as the formal parameter.
Previous | Next | Contents | Index |