PL/I

PL/I

PL/I

 View Only
  • 1.  PL/1: How can I specifiy a procedure with a variable number of parameters?

    Posted Fri January 11, 2013 09:27 AM
    Hi!
     
    Having a "C" background, I want to implement a procedure which I can call with a variable
    number of parameters. In "C" you have a varargs.h
    If my intention is unclear, maybe
    helps understand my  question.
     
    My compilation unit is a "package", and the procedure is using locally inside the package.
     
    To give an example:
     
    CALL  INIT_SET_OF_VALUES(VALUE1);
    or
    CALL INIT_SET_OF_VALUES(VALUE1, VALUE2, VALUE3);
     
    I want to avoid a calls/definitions like
     
    /* provide the number  of actual provided parameters */
    CALL INIT_SET_OF_VALUES(n,  VALUE1, ... , VALUEn);
     
    or
     
    /* define the procedure for  a maximum number of params and provide always  
       as many parameters as defined. If less parameters are available a specific 
       "nullValue" is used to fillup the param list and 
        signal: this formal parameter has no actual value                  */ 
    CALL INIT_SET_OF_VALUES(VALUE1, nullValue, nullValue);  
      
    Questions: 
    Q-1: Is there a way to do it (without using an assembler part to determine the # of params) 
    Q-2: How to declare such a procedure? 
    Q-3: How to pick the number of parameters provided 
     
    I was not able to find a hint in the PL/1 manuals.
     
    Regards, JustAFreeName  
     
    JustAFreeName


  • 2.  Re: PL/1: How can I specifiy a procedure with a variable number of parameters?

    Posted Sun January 13, 2013 09:18 PM
    Use the OPTIONAL attribute for parameters.
    For your scheme, the first parameter can be normal, and subsequent ones can be given
    the OPTIONAL attribute.
    Be sure to use the OMITTED built-in function in the subroutine/function before using an
    optional parameter.
    Robin400


  • 3.  Re: PL/1: How can I specifiy a procedure with a variable number of parameters?

    Posted Tue January 15, 2013 03:52 AM
     Hi Robin400.
     
    Thx for the reply and guideline. 
    I'll try the "OPTIONAL/ OMITTED" scheme.
     
    This scheme matches my visual perception in a prefect way
     
    Thx a lot!
    Regards, JustAFreeName. 
     
    JustAFreeName


  • 4.  Re: PL/I: How can I specifiy a procedure with a variable number of parameters?

    Posted Sun January 13, 2013 11:13 PM
     Alternatively, you can use the GENERIC facility:
     
    declare SUB  generic (
      e1 when (*),
      e2 when (*, *),
      e3 when (*, *, *) );
    e1: procedure (p1); ...
    end;
    e2: procedure (p1, p2); ...
    end e2;
    e3: procedure (p1, p2, p3); ...
    end e3;
     
    Then you can use:
    call e1(a1);
    and
    call e2(a1, a2);
    and
    call e3(a1, a2, a3);
     
    The asterisks may be replaced by attributes, if required.
    Robin400


  • 5.  Re: PL/1: How can I specifiy a procedure with a variable number of parameters?

    Posted Fri January 20, 2017 06:08 PM

    If the function called is in another language (i.e. C) then you may be able to declare it with no parameter descriptions:

    dcl printf ext('PRINTF') /* I don't remember the exact external name for printf, it varies by which library you have */    entry options(byvalue nodescriptor) returns( fixed(31) binary byvalue );

    Then call it with whatever parameters you need:

    varz_string ="Here is a number %d";

    my_int = 5;

    call fprintf( varz_string, my_int);

    I have not tested this, but it seems to match the info in the PL/I programming guide (chapter15, "ILC with C").

    Good luck. 

    Frank

    fomyers