A formal parameter is located in the header of the routine declaration, and consists of input parameters, output parameters, and routine parameters. A routine uses input parameters to obtain values; it uses output parameters to return values; and it uses routine parameters to call another routine named by a formal parameter. The formal parameter establishes the semantics, the data type, and the required passing mechanism of the parameter. See the "HP Pascal Language Reference Manual" for more information on parameter passing mechanisms. Syntax: [[({ {value-parameter-spec | variable-parameter-spec | routine-parameter-spec | foreign parameter-spec} };...)]] The specific format depends on the semantics (value, variable, routine, or foreign) of the formal parameter you are declaring. A formal value parameter represents a local variable within the called routine. When you specify value semantics, the address of the actual parameter is passed to the called routine, which then copies the value from the specified address to its own local storage. The routine then uses this copy. The copy is not retained when control returns to the calling block. Therefore, if the called routine assigns a new value to the formal parameter, the change is not reflected in the value of the actual parameter. Syntax: {identifier},... : [[attribute-list]] {type-id | conformant-parameter-syntax | undiscriminated-schema-name} [[:= [[mechanism-specifier]] default-value]] A formal variable parameter represents another name for a variable in the calling block. It is preceded by the reserved word VAR. When you specify variable semantics, the address of the actual parameter is passed to the called routine. In contrast to value semantics, the called routine directly accesses the actual parameter. Thus, the routine can assign a new value to the formal parameter during execution and the changed value is reflected immediately in the calling block (the value of the actual parameter changes). Syntax: VAR {identifier},... : [[attribute-list]] {type-id | conformant-parameter-syntax | undiscriminated-schema-name} [[:= [[mechanism-specifier]] default-value]] To write a routine that invokes another routine whose effect is not determined until the program is executed, use routine parameters. To declare a procedure or a function as a formal parameter to another routine, you must include a complete routine heading in the formal parameter list. You can also associate a foreign mechanism specifier and a default value with a formal procedure or function parameter. Syntax: [[attribute-list]] PROCEDURE procedure-id [[formal-parameter-list]] [[ := [[mechanism-specifier]] default-value ]] or [[attribute-list]] FUNCTION function-id [[formal-parameter-list]] : [[attribute-list]] result-type-id [[ := [[mechanism-specifier]] default-value ]] When declaring an external routine (one written in a language other than Pascal) that is called by a VSI Pascal routine, you must specify not only the correct semantics but the correct mechanism as well. To allow you to obtain these passing mechanisms, VSI Pascal provides foreign mechanism specifiers and the passing mechanism attributes. See the "HP Pascal Language Reference Manual" for complete details on formal parameter semantics.
1 – identifier
The 'identifier' is the name of the formal parameter. Multiple identifiers must be separated with commas.
2 – attribute_list
The 'attribute-list' is one or more optional identifiers which provide information about the formal parameter.
3 – mechanism_specifier
VSI Pascal provides the foreign mechanism specifiers %IMMED, %REF, %DESCR, and %STDESCR, which precede a formal parameter in the declaration of an external routine. If the formal parameter does not represent a routine, the mechanism specifier must precede the parameter name. If the formal parameter represents a routine, the specifier must precede the reserved word PROCEDURE or FUNCTION in the parameter declaration. In addition, it is possible to use the passing mechanism attributes [IMMEDIATE] and [REFERENCE] in a formal parameter's attribute list to obtain the same behavior as %IMMED or %REF, respectively. A %REF or [REFERENCE] formal parameter requires actual parameters to be passed by reference. %REF or [REFERENCE] implies variable semantics unless the actual parameter is an expression; in that case, it implies foreign value semantics. An %IMMED or [IMMEDIATE] formal parameter requires actual parameters to be passed with the by immediate value mechanism and always implies value semantics. %IMMED or [IMMEDIATE] cannot be used on formal parameters of type VARYING, or on conformant array and conformant VARYING parameters. A %DESCR formal parameter requires actual parameters to be passed with the by descriptor mechanism and interprets the semantics as %REF or [REFERENCE] does. A %STDESCR formal parameter requires actual parameters to be passed with the by string descriptor mechanism. An actual parameter variable of type PACKED ARRAY OF CHAR implies variable semantics. An actual parameter expression of either type PACKED ARRAY OF CHAR or type VARYING OF CHAR implies foreign value semantics. You cannot use %STDESCR on formal procedure and function parameters.
4 – type_id
A type identifier is the type identifier of the parameters in this parameter section.
5 – undiscriminated_schema_name
The name of an undiscriminated schema type. If you have a user-defined, formal parameter of an undiscriminated schema type, the corresponding actual parameter must be discriminated from the same schema type as that of the formal parameter. When you pass a string expression to a formal, value parameter of type STRING, the actual parameter's current length (not its declared maximum length) becomes both the maximum length and the current length of the formal parameter.
6 – conformant_parameter
A conformant parameter is a syntax of a conformant array or a conformant VARYING parameter that represents a set of types that are identical except for their bounds. The bounds of a conformant parameter are determined each time a corresponding actual parameter is passed. The bounds of an actual parameter are available within the routine through identifiers declared in the schema. A conformant parameter can only appear within a formal parameter list. The form of a conformant array parameter is as follows: ARRAY [{lower-bound-id .. upper-bound-id : [[attribute-list]] index-type-id};...] OF [[attribute-list]] {type-id | conformant-parameter-syntax} PACKED ARRAY [lower-bound-id .. upper-bound-id : [[attribute-list]] index-type-id] OF [[attribute-list]] type-id The form of a conformant VARYING parameter is as follows: VARYING [upper-bound-id] OF [[attribute-list]] CHAR The 'lower-bound-id' is an identifier that represents the lower bound of the conformant array's index. The 'upper-bound-id' is an identifier that represents the upper bound of the conformant array's index. The 'attribute-list' is one or more optional identifiers that provide additional information about the conformant array. The 'index-type-id' is the type identifier of the index, which must denote an ordinal type. The 'type-id' is the type identifier of the array components, which can denote any type.
7 – default_value
VSI Pascal allows you to supply default values for formal parameters. Using default parameter values, you do not need to pass actual parameters. Also, you can specify an actual parameter in the position of a formal parameter whose default value you want to override. This value can be any constant value of the type. It must be a legal actual parameter for the kind of formal parameter with which the default is associated. The default-value is evaluated when the routine is declared.