HP 3000 Manuals

Procedure Call Statement [ SPL to HP C/XL Migration Guide ] MPE/iX 5.0 Documentation


SPL to HP C/XL Migration Guide

Procedure Call Statement 

          Table 6-13.  Procedure Call Statement 

----------------------------------------------------------------------------------------------
|                                             |                                              |
|                     SPL                     |              HP C/XL Equivalent              |
|                                             |                                              |
----------------------------------------------------------------------------------------------
|                                             |                                              |
| procedure-call-statement:                   | function-call-statement:                     |
|                                             |                                              |
|      1. procedure-id                        |      1. function-id ( ) ;                    |
|                                             |                                              |
|      2. procedure-id ( )                    |      2. function-id ( ) ;                    |
|                                             |                                              |
|      3. procedure-id ( actual-parm [,...] ) |      3. function-id ( actual-parm [,...] ) ; |
|                                             |                                              |
----------------------------------------------------------------------------------------------
|                                             |                                              |
| A procedure call causes a control transfer  | Same as SPL, using a function call.          |
| to a procedure, supplying any required      |                                              |
| parameters.                                 | As shown in format 1, HP C/XL requires the   |
|                                             | parentheses even if there are no actual      |
| Formats 1 and 2 are equivalent.             | parameters.                                  |
|                                             |                                              |
----------------------------------------------------------------------------------------------
|                                             |                                              |
| actual-parm:                                | actual-parm:                                 |
|                                             |                                              |
|      a. simple-variable-id                  |      a-r. &simple-variable-id                |
|                                             |      a-v. simple-variable-id                 |
|      b. array/pointer-id                    |      b-r. array/pointer-id                   |
|                                             |      b-v. array/pointer-id "[" 0 "]"         |
|      c. procedure-id                        |      c-r. function-id                        |
|      d. entry-id                            |      d-r. (No equivalent; must be recoded)   |
|      e. label-id                            |      e-r. (No equivalent; must be recoded)   |
|      f. array/pointer-id ( index )          |      f-r. &array/pointer-id "[" index "]"    |
|                                             |      f-v. array/pointer-id "[" index "]"     |
|      g. arithmetic-expression               |      g-v. arithmetic-expression              |
|      h. logical-expression                  |      h-v. logical-expression                 |
|      i. assignment-statement                |      i-v. assignment-expression              |
|      j. *                                   |      j.     (No equivalent; must be recoded) |
|                                             |                                              |
----------------------------------------------------------------------------------------------
|                                             |                                              |
| Parameter formats a, b, and f may be        | Parameter formats marked with "-r" are       |
| pass-by-reference or pass-by-value.  Their  | pass-by-reference.  Formats marked with      |
| pass-by-value use is also included in       | "-v" are pass-by-value.  In HP C/XL, while   |
| formats g and h.  Formats c, d, and e are   | all parameters are pass-by-value,            |
| pass-by-reference only.  Formats g, h, and  | pass-by-reference is achieved by passing a   |
| i are pass-by-value only.  Format j may be  | pointer value to a pointer parameter.        |
| either.                                     | Function-ids are passed as pointers;         |
|                                             | unsubscripted array-ids are passed as        |
|                                             | pointers to their first elements.  Array,    |
|                                             | pointer, and function formal parameters      |
|                                             | expect pointer actual parameters.            |
|                                             |                                              |
----------------------------------------------------------------------------------------------
|                                                                                            |
|                                         Continued                                          |
|                                                                                            |
----------------------------------------------------------------------------------------------

          Procedure Call Statement(cont.) 

---------------------------------------------------------------------------------------------
|                                             |                                             |
|                     SPL                     |             HP C/XL Equivalent              |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Whether an actual-parm is pass-by-value or  | Similar to SPL, except that HP C/XL         |
| pass-by-reference depends on the definition | performs no type checking whatsoever.       |
| of the procedure.  SPL performs strict      |                                             |
| type-checking to ensure that parameters     | The programmer must ensure that pointers    |
| match.                                      | are passed to pointers, integers are passed |
|                                             | to integers, and reals are passed to reals. |
|                                             | Note that all char, enum, and int types are |
|                                             | expanded to [unsigned] long int types, and  |
|                                             | float is expanded to double when the actual |
|                                             | parameters are evaluated.  The passed long  |
|                                             | int, double, and pointer values are         |
|                                             | converted to the declared formal type when  |
|                                             | they are received by the function.          |
|                                             |                                             |
|                                             | Fortunately, because SPL is so strict, the  |
|                                             | conversion boils down to getting the        |
|                                             | pass-by format correct.                     |
|                                             |                                             |
---------------------------------------------------------------------------------------------

          Table 6-14.  Procedure Call Statement Examples 

---------------------------------------------------------------------------------------------
|                                             |                                             |
|                     SPL                     |             HP C/XL Equivalent              |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
|                                             |                                             |
|      PROCEDURE P1 ( VALP );                 |      void P1 ( VALP )                       |
|         VALUE VALP; INTEGER VALP;           |         unsigned short VALP;                |
|         BEGIN                               |         {                                   |
|            GVAR := VALP;                    |         GVAR = VALP;                        |
|         END;                                |         }                                   |
|                                             |                                             |
|      PROCEDURE P2 ( REFP );                 |      void P2 ( REFP )                       |
|         INTEGER REFP;                       |         unsigned short *REFP;               |
|         BEGIN                               |         {                                   |
|            GVAR := REFP;                    |         GVAR = *REFP;                       |
|         END;                                |         }                                   |
|      ...                                    |      ...                                    |
|      <<main program>>                       |      /*main function*/                      |
|      ...                                    |      ...                                    |
|      P1(V);  <<pass-by-value>>              |      P1(V);  /*pass-by-value*/              |
|      P2(V);  <<pass-by-reference>>          |      P2(&V); /*pass-by-reference*/          |
|      ...                                    |      ...                                    |
|                                             |                                             |
---------------------------------------------------------------------------------------------

In the examples above, notice that when P2 was called (in HP C/XL), the
address of the variable was explicitly specified with the "&" operator.
If the actual parameter had been an unsubscripted array-id or a string
literal, the "&" would have been omitted.  In HP C/XL, if an identifier A
is declared to be an array, the following function call expressions are
equivalent:

     P3(A); and P3(&A[0]);

The data type void specifies that the function does not return a value.
See "PROCEDURE Declaration" for details.

String Literals 

HP C/XL allows string literals to be passed as actual parameters, which
is not possible in SPL. Thus, the following SPL code

     MOVE BARRAY:="test string";
     PROCB(BARRAY);  <<called with byte array BARRAY>>

used to pass a string to an SPL procedure via a byte array, may be
rewritten in HP C/XL as:

     PROCB("test string");

HP C/XL will create storage for the string, and pass its address to PROCB
as a "pointer to char" (a byte address).  This is a more straightforward
means of accomplishing the same operation as the SPL example.

Stacking Parameters 

By directly manipulating the hardware stack in MPE V, SPL programmers can
set up parameters to a procedure directly and then call the procedure
using "*" actual parameters.

There is no equivalent in HP C/XL. However, replacing the "*"s in the
parameter list with the stacked values is functionally equivalent.
(Usually, the procedure call is preceded by assignments to TOS, which can
be thus eliminated.)

This technique is used in SPL mostly to optimize runtime performance, not
to gain otherwise unavailable functionality.  A simple rewrite will
eliminate any explicit references to the stack.

Missing Parameters in Procedure Calls 

If an SPL procedure is declared with OPTION VARIABLE, parameters may be
omitted from the actual parameter list when the procedure is called.

HP C/XL provides the varargs macros to enable variable-length actual
parameter lists.  This feature is described further in "Options", and in
the HP C/XL Library Reference Manual.

Passing Labels as Parameters 

SPL has an elaborate facility for passing labels to procedures as actual
parameters.  When control is transferred to the label, the procedure
automatically performs an exit from itself (and from any other procedures
in the calling sequence between this one and the one containing the
passed label) prior to transferring control to the label location.  This
effectively "unwinds" a stack of procedure calls, and is most often used
in error recovery.

HP C/XL does not permit labels to be passed as parameters.  These
situations can (and must) be rewritten, possibly by declaring a global
flag variable to indicate error conditions.  This flag should be tested
by functions to determine if processing is to be terminated prematurely.

Another approach is to use the longjmp and setjmp functions described in
the HP C/XL Library Reference Manual.

Passing Procedures as Parameters 

An SPL procedure (e.g., A) may be passed to another procedure (e.g., B)
as a pass-by-reference parameter.  When A is called from B, the actual
parameters supplied in the parameter list at the time of the call are
assumed to be pass-by-reference.  Pass-by-value actual parameters must be
placed on the stack and specified with the "*" symbol in the procedure
call.  OPTION VARIABLE passed procedures require more work, including the
fabrication on the stack of a special mask word.

In HP C/XL, a function-id may be passed as an actual parameter.  There
are no particular restrictions on the actual parameter list when the
passed function is called.  For example,

     main()
     {
        void callf(), calledf(); /* declares two functions */

        callf(calledf); /* execute callf, passing calledf */
     } /* end of main */

     void callf(func) /* function to call a function */
        void (*func)(); /* func is pointer to function returning void */
     {
        (void) func(); /* call the passed function */
     } /* end of callf */

     void calledf() /* function that will be passed */
     {
        printf("called calledf!\n");
     } /* end of calledf */

For further information on OPTION VARIABLE cases, see "Missing Parameters
in Procedure Calls" above.



MPE/iX 5.0 Documentation