| United States-English |
|
|
|
![]() |
HP Pascal/HP-UX Programmer's Guide > Chapter 10 Intrinsics Using Intrinsics |
|
To use an intrinsic, your program must specify the intrinsic file in which its definition resides and declare the intrinsic with the INTRINSIC directive. How your program can declare the intrinsic as a routine — specifying all, part, or none of its formal parameters — depends upon its definition in the intrinsic file. This section explains:
When compiling a program that references an intrinsic, the compiler reads the intrinsic definition from an intrinsic file. The intrinsic file can be the default intrinsic file for the system, or it can be one that you or another programmer built (see “How to Build or Change an Intrinsic File ”). The program can specify different intrinsic files for different intrinsics. The SYSINTR compiler option determines the intrinsic file. If the program does not contain a SYSINTR option, or if the SYSINTR option does not specify a file name, the compiler reads intrinsic definitions from the default intrinsic file. (The default intrinsic file is system-dependent. See Appendix A “MPE/iX Dependencies ” for the MPE/iX operating system; Appendix B “HP-UX Dependencies ” for the HP-UX operating system.) Otherwise, the compiler reads intrinsic definitions from the file that the SYSINTR option specifies, until another SYSINTR option specifies another file. (See the HP Pascal/iX Reference Manual or the HP Pascal/HP-UX Reference Manual, depending on your implementation, for more information on the SYSINTR compiler option.) To list an intrinsic file, use the LISTINTR compiler option (refer to the HP Pascal/iX Reference Manual the HP Pascal/HP-UX Reference Manual, depending on your implementation, for more information on the LISTINTR compiler option).
The INTRINSIC directive allows a program to access an intrinsic routine. It follows the routine declaration. Example
The program p can call the intrinsic procedure FSETMODE because it declares it with the INTRINSIC directive. The system name of an intrinsic is the name by which the operating system recognizes it, the name that it has in the intrinsic file. The system names of some intrinsics are illegal in HP Pascal. If you want to use such an intrinsic in your program, give it a legal name in your program and specify its system name with the ALIAS compiler option (refer to the HP PascaliX Reference Manual the HP Pascal/HP-UX Reference Manual, depending on your implementation, for more information on ALIAS). Example
The name P'F'INFO is illegal in HP Pascal because it contains single quotes. The program q can call the intrinsic procedure P'F'INFO by the name pfileinfo because it declares it with the INTRINSIC directive and specifies its system name with the ALIAS compiler option. An intrinsic's actual parameters are those with which your program calls it. Its intrinsic parameters are those in its definition, in the intrinsic file. Its formal parameters are those that your program declares for it. Formal parameters are optional. If you do not declare them, you can pass the intrinsic actual parameters of types that would otherwise be incompatible. Usually, programmers want this flexibility; therefore, they rarely declare formal parameters. If you do not declare a formal parameter, its actual parameters are type-checked against their corresponding intrinsic parameters. Type checking depends upon whether the intrinsic parameter is a reference, value, or function or procedure parameter. The following subsections explain these three cases, using these terms:
A reference parameter is a parameter that is passed by reference. VAR, ANYVAR, and READONLY parameters are reference parameters. All actual reference parameters must be alignment-compatible with their corresponding intrinsic parameters. Actual VAR and READONLY parameters must also be size-compatible and intrinsic-compatible with their corresponding intrinsic parameters. An intrinsic and an actual reference parameter are intrinsic-compatible if their types are in the same row of Table 10-1 “Intrinsic-Compatible Intrinsic and Actual Reference Parameter Types ”. The intrinsic parameter type is the type of the intrinsic parameter, as the intrinsic file declares it. The actual parameter type is the type of the actual parameter. Table 10-1 Intrinsic-Compatible Intrinsic and Actual Reference Parameter Types
A value parameter is a parameter that is passed by value. All parameters except VAR, ANYVAR, READONLY, function, and procedure parameters are value parameters. An actual value parameter of a structured type (array, record, or set) must be the same size as its corresponding intrinsic parameter. An actual value parameter of an unstructured type must be assignment-compatible with its corresponding intrinsic parameter. Table 10-2 “Intrinsic-Compatible Intrinsic and Actual Value Parameter Types ” shows which intrinsic and actual value parameter types are intrinsic-compatible. It also shows, for each intrinsic parameter type, which of the compatible actual parameter types are converted to that intrinsic parameter type, and which are not. The intrinsic parameter type is the type of the parameter as the intrinsic file declares it. The actual parameter type is the type of the actual parameter. Table 10-2 Intrinsic-Compatible Intrinsic and Actual Value Parameter Types
A function or procedure parameter is a parameter that is a routine. The compiler only checks that the actual parameter for a function or procedure parameter is a routine. You are responsible for making sure that the actual parameter is what the intrinsic expects. If you use a string variable as an actual value parameter to an intrinsic routine, HP Pascal passes a copy of the data portion only of the string. The length portion is ignored. If you use a string variable as an actual reference parameter to an intrinsic routine, HP Pascal passes the address of the data portion of the string, and not the string length. If the intrinsic returns data in the string variable, you must determine and update the length of the string when the intrinsic returns control to your program. There are a number of ways to obtain and update the string length:
Example This example demonstrates the sequence of filling a string with blanks, calling an intrinsic that returns a value in the string, and updating the string length.
A function type must be specified when using the intrinsic directive with functions. A formal function type is compatible with an intrinsic function type as long as the size of the formal type matches the size of the intrinsic type.
Example
Assuming the date did not change, the output is unexpected:
Function cal_16 shows the correct definition; a and b should be declared as bit16. If you want stricter type checking for an intrinsic's actual parameters, you can declare formal parameters for some or all of its intrinsic parameters. Then, actual parameter types are compared to their corresponding formal parameter types, not to their corresponding intrinsic parameter types. This type checking is as strict as that for the parameter of a nonintrinsic routine: if the actual parameter is a reference parameter, it must be of the same type as the formal parameter; if the actual parameter is a value parameter, it must be assignment-compatible with the formal parameter. If an intrinsic is defined without an extensible parameter list, you cannot declare it with one. If an intrinsic is defined with an extensible parameter list, you can declare it with or without one. If you declare the intrinsic with an extensible parameter list, you must declare at least as many nonextensible (required) parameters as the definition does. If you declare the intrinsic without an extensible parameter list, you must declare all of its nonextensible (required) parameters. Example 1 The intrinsic file defines the intrinsic Pascal procedure intr this way:
The program can declare intr in any of these ways:
The program cannot declare intr in any of these ways:
If you supply default values for the formal parameters that you declare, your default values override those supplied by the intrinsic definition. Example 2 The intrinsic file defines the intrinsic Pascal procedure intr this way:
If the program declares intr this way
Then the default value of a is 35 (not 10) and the default value of b is 60 (not 20). If you declare a formal parameter, you must give it a type that is compatible with the type of its corresponding intrinsic parameter. Compatibility rules are different for reference and value parameters. A formal reference parameter is compatible with its corresponding intrinsic parameter if any of the following is true:
An intrinsic and a formal reference parameter are intrinsic-compatible if their types are in the same row of Table 10-3 “Intrinsic-Compatible Intrinsic and Formal Reference Parameter Types ”. The intrinsic parameter type is the type of the intrinsic parameter, as the intrinsic file declares it. The formal parameter type is the type of the formal parameter in your program. Table 10-3 Intrinsic-Compatible Intrinsic and Formal Reference Parameter Types
Table 10-4 “Compatible Intrinsic and Formal Reference Parameter Types ” shows which intrinsic and formal reference parameter types are compatible. The intrinsic parameter type is the type that the intrinsic parameter has in the intrinsic file; the formal parameter types are the types that you can give the formal parameter when you declare it in your program. Table 10-4 Compatible Intrinsic and Formal Reference Parameter Types
A formal value parameter is compatible with its corresponding intrinsic parameter if any of the following is true:
An intrinsic and formal value parameter are intrinsic-compatible if their types are in the same row of Table 10-5 “Intrinsic-Compatible Intrinsic and Formal Value Parameter Types ”. The intrinsic parameter type is the type of the intrinsic parameter, as the intrinsic file declares it. The formal parameter type is the type of the formal parameter. Table 10-5 Intrinsic-Compatible Intrinsic and Formal Value Parameter Types
Your program must use an intrinsic procedure as a procedure, but it can use an intrinsic function as a function, a procedure, or both. To use an intrinsic function as a function, declare it as a function in your program, including its result type in the declaration. To use an intrinsic function as a procedure, declare it as a procedure in your program, omitting the result type. To use an intrinsic function as both a function and a procedure, declare it both ways, giving the routine different names in your program. Use the ALIAS compiler option to associate the intrinsic's system name with the names you have given it. If you declare an intrinsic function as a procedure only, you cannot call it as a function. Example The intrinsic file defines the intrinsic Pascal functions f1 and f2 this way:
The Pascal program prog declares the function f1 as a procedure. It cannot call it as a function. It declares the function f2 as a function (which it calls ffunc) and as a procedure (which it calls fproc), using the compiler option ALIAS to associate them with the system name f2. The program cannot call fproc as a function.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||