Variable number of parameters possible? 
Author Message
 Variable number of parameters possible?

Quote:

> Is it possible (and safe) to call an internal or external procedure with a
> variable number of parameters, and have the called procedure determine the
> actual number of parameters received?  If so, could someone please post an
> example?  This is with OS PL/I Version 2 (both calling and called programs).

Optional parameters are available with PL/I for OS/2.


Tue, 02 Oct 2001 03:00:00 GMT  
 Variable number of parameters possible?

Quote:

> Is it possible (and safe) to call an internal or external procedure
> with a variable number of parameters, and have the called procedure
> determine the actual number of parameters received?

The calling-program can do the mapping:

  DECLARE generic_name GENERIC
      (entry_reference1 WHEN ( )
       entry_reference2 WHEN ( ,) );

   CALL generic_name ('One Argument')   invokes  entry_reference1,
while
   CALL generic_name ('Two', 'Arguments')   invokes  entry_reference2,

and those two names can be identified as ENTRY points.



Tue, 02 Oct 2001 03:00:00 GMT  
 Variable number of parameters possible?

Quote:

> Is it possible (and safe) to call an internal or external procedure with a
> variable number of parameters, and have the called procedure determine the
> actual number of parameters received?

One answer I didn't see is that you could call the procedure with an
argument count and the address of an array of pointers to the actual
arguments. This won't pass descriptors or allow expressions as arguments
but might be a good solution depending on what you want to do.


Tue, 02 Oct 2001 03:00:00 GMT  
 Variable number of parameters possible?
I don't know if/how PL/1 or most other HLL's could reliably and generally
tell you how many parameters you're called with, but you may be able to use
an application convention, e.g. for each subroutine, decide how many
parameters you will always use as a minimum, and depending on their values,
then you'll know how many other parameters there are. I know this works
fine in Cobol/390 and Cobol II. I'm not sure about PL/1. Perhaps every LE
compatible HLL (and most other HLL implementations) is set up flexibly
enough to handle variable numbers of parameters as long as no invalid
(missing) parameter is ever referenced. Comments?

Robert M. Pritchett, President - RMP Consulting Partners LLC

"Quality means doing it right the first time!"
See http://www.headhunter.net/jobstv/0j/j04651mjxt8trch80j.htm?ShowJob
Contractors: tired of hearing "W-2 only"? Join us and let us help you get
that same contract on a 1099 as a self-employed independent contractor!


Quote:
>Is it possible (and safe) to call an internal or external procedure with a
>variable number of parameters, and have the called procedure determine the
>actual number of parameters received?



Wed, 03 Oct 2001 03:00:00 GMT  
 Variable number of parameters possible?

Quote:
>I don't know if/how PL/1 or most other HLL's could reliably and generally
>tell you how many parameters you're called with, but you may be able to use
>an application convention, e.g. for each subroutine, decide how many
>parameters you will always use as a minimum, and depending on their values,
>then you'll know how many other parameters there are. I know this works
>fine in Cobol/390 and Cobol II. I'm not sure about PL/1. Perhaps every LE
>compatible HLL (and most other HLL implementations) is set up flexibly
>enough to handle variable numbers of parameters as long as no invalid
>(missing) parameter is ever referenced. Comments?

This is correct, as long you don't use the declared but not provided
parameters. And - be aware! - a PLI-function (ie. returning something)
always will expect a hidden parameter after all declared to return the
return-value!

Quote:
>>Is it possible (and safe) to call an internal or external procedure with a
>>variable number of parameters, and have the called procedure determine the
>>actual number of parameters received?

No, an internal function is completely known to the compiler and he
won't allow to call it without the right number of parameters.

CUL8R!

Ing. Michael Fitz
A-2410 Hainburg; Carnuntumstr. 21

=== PGP-Key on request ===



Thu, 04 Oct 2001 03:00:00 GMT  
 Variable number of parameters possible?

Quote:

>You may find it easier to use OPTIONS(COBOL) on both the entry and the
>procedure declarations.

This is very recommended, because it makes argument passing easier (no
clobbering with pointers etc.), and the environment will be only build
up at the first call saving a lot of execution time.

Quote:

>>I know this is possible with assembler by checking the X'80' bit of the
>last
>>parameter, but I don't know for sure if it's doable with PL/I.  I could
>tinker
>>and try to figure it out, but I'd prefer a definitive answer if anyone has
>>one.  Thanks!

I've written such a routine. It's quite simple (I've not copied the
working source because I don't have it ready alhere - I've written it
down from my head on the fly. No warranty given!!):

PARMCNT CSECT
PARMCNT AMODE ANY
PARMCNT RMODE ANY
 USING *,R15
 STM R14,R12,12(R13) . Save all regs
 L R4,4(R13) . A(Callers Savearea)
 L R6,6*4(R4) . R1 at entry to caller
 XR R8,R8 . Clear counter
 LTR R6,R6 .No Parameters are indicated by R1=0
 BZ DONE
CLOOP EQU *
 LA R8,1(R8) . Count
 L R5,0(R6) . A(Parameter #n  for caller)
 LTR R5,R5
 BM DONE . High-order-bit set - last parameter
 LA R6,4(R6) . Next caller's parameter address
 B CLOOP
DONE EQU *
 L R6,0(R1) . Get A(return)
 STH R8,0(R6)
 LM R14,R12,12(R13)
 BR R14

This works as long the standard-IBM calling-sequence is obied.

Usage:

a) PLI:

DCL PARMCNT ENTRY RETURNS(BIN FIXED(15));

IF PARMCNT() > 3 THEN
  PUT SKIP LIST('I was called with 4 or more paremters');

b) COBOL:

77 PARMCOUNT PIC S9999 COMP.

CALL 'PARMCNT' USING BY REFERENCE PARMCOUNT.

IF PARMCOUNT GREATER 3  
  DISPLAY 'I was called with 4 or more parameters'

Attention when used with PLI:

PARMCNT must be used on nesting level 0 (ie not within a local proc),
otherwise it will return the (already known) number of parameters of
this subproc and not of the outer proc.

CUL8R!

Ing. Michael Fitz
A-2410 Hainburg; Carnuntumstr. 21

=== PGP-Key on request ===



Thu, 04 Oct 2001 03:00:00 GMT  
 Variable number of parameters possible?

Quote:

> I know this is possible with assembler by checking the X'80' bit of the last
> parameter, but I don't know for sure if it's doable with PL/I.  I could tinker
> and try to figure it out, but I'd prefer a definitive answer if anyone has
> one.  Thanks!

Try this:

   DCL DUMMY        LABEL VARIABLE;
   DCL 1 GET_DSA BASED (ADDR (DUMMY)),
        3 LABELADDR PTR,
        3 DSA_ADDR  PTR;
   DCL DSAPTR       PTR;
   DCL 1 DSA BASED (DSAPTR),
        3 FLAGS     CHAR (4),
        3 BACKPTR   PTR,
        3 FILLER    CHAR (4),
        3 R14       PTR,
        3 R15       PTR,
        3 R0        PTR,
        3 R1        PTR;           /* POINTS TO ARGUMENT LIST         */
                                   /* ASSUME RANGE CHECKING IS OFF    */
   DCL ARGLIST (1)  PTR BASED (DSA.R1);
   DCL I            FIXED BIN (15);
   DCL ADDR         BUILTIN;
   DCL BINARYVALUE  BUILTIN;
 HERE:
   DUMMY = HERE;                   /* FIND OUR DSA ADDRESS            */
   DSAPTR = GET_DSA.DSA_ADDR;
   DSAPTR = DSA.BACKPTR;           /* FIND CALLER'S DSA               */
   DO I = 1 BY 1                   /* COUNT THE PARMS                 */
      UNTIL (BINARYVALUE (ARGLIST (I)) < 0);
   END;
   /* The creatively-named variable 'I' now contains the argument count
*/

I haven't tested this, but it compiles cleanly. I'll leave it as an
optional exercise for the reader to cater for the case where NO
arguments are passed, but this should be enough to get you started.

It only works for PL/I 1.x or 2.x on MVS. The new-fangled electric
versions, such as 'PL/I for MVS', do not set the high bit of the last
argument pointer, apparently.

Rob Watson
(I'm not representing IBM or its PL/I labs here. This is personal
assistance from a PL/I-ophile)



Fri, 05 Oct 2001 03:00:00 GMT  
 Variable number of parameters possible?

Quote:

> No, an internal function is completely known to the compiler and he
> won't allow to call it without the right number of parameters.

You can, however, write a macro that generates a call to a function,
adding default parameters.

Klaus Johannes Rusch
--

http://www.atmedia.net/KlausRusch/



Fri, 05 Oct 2001 03:00:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Variable Numbers of Parameters in Fortran Calls

2. Variable number of parameters

3. IF statement possible with parameter????

4. Is it possible to have long parameter arrays?

5. Number of Parameters

6. adding all possible combinations of numbers in an array

7. on determining number of parameters actually passed

8. *** Reading Possible Negative Number ***

9. Possible problem with float numbers.

10. How to get number of actual parameters in subroutine

11. External Call with variable parameter list

12. J and OLE (Excel): variables in xlreadr parameters?

 

 
Powered by phpBB® Forum Software