On 4/10/2012 11:15 AM, Frank Swarbrick wrote:
I only happened to learn PL/I this weekend,

Well I'm impressed!

so take this with a grain of salt,
but can't you activate THEFUNCTION with a call rather than as a function in
order to be able to use LINKAGE(SYSTEM)? And then use PLIRETV() in order to get
the return code?

1. Yes you can, theoretically, set this up as a procedure

2. And, yes, the call to PLIRETV should work (although in
   the literature it says for this to work the called
   program should have made a call to PLIRETC, the effect
   from the C function will probably match that)

3. But the problem he is concerned with: how to pass
   three parameters or five parameters and have the
   C function know which have been passed

   If he is counting on the end-of-list flag, then
   the C function must have something like

     #pragma linkage(thefunction,OS)

   but it's not clear if that is the case here

   That's why I wanted to see how he checks for the
   number of parms in his C code.


Also, to turn on the end-of-list flag, the call from
the PL/I program will have to have options(asm), so:

  call thefunction(magic, inbuff, inbufflen, outbuff, outbufflen) options(asm);

or

  call thefunction(magic, inbuff, inbufflen) options(asm);


Also note that if the subroutine were declared as a function,
then options(asm) is not allowed.



declare THEFUNCTION entry options(ASM RETCODE LINKAGE(SYSTEM));
(I think LINKAGE(SYSTEM) is redundant here.)


call THEFUNCTION(one, two, three);
display(pliretv());
call THEFUNCTION(one, two, three, four, five);
display(pliretv());

(Not sure if the declare entry requires the parms to be declared.)


Maybe you can even wrap the above into a PL/I function so that your PL/I 
programs can invoke it as a function.

Just a WAG.  Good luck!

Frank



----- Original Message -----
From: Phil Smith<p...@voltage.com>
To: IBM-MAIN@bama.ua.edu
Cc:
Sent: Tuesday, April 10, 2012 9:57 AM
Subject: Re: PL/I with variable PLISTs (was: LE C calling HLASM)

Steve Comstock wrote:
I'm confused here, because the title of the thread
is 'C calling HLASM' and here we are talking about
PL/I.

Yeah, true...topic drift. Renamed.

So what's really going on here that is the mystery?

My guess is: you have a C function that you want to
call from, in this instance, a PL/I program. Right?

Right.

Can you show us the definition of the C function
(not the body, just the definition of parameters
along with any pragma statements you might have,
and compiler options relevant to calls / function
references)?

See below.

Can you show us how you invoke the function from
C, COBOL, and Assembler? That is, some sample calls
or function references that work successfully, both
with two arguments and four arguments (BTW: do you
allow the output buffer to be specified without the
last length argument? How about no output buffer
but with a length? In other words, must the user
specify exactly two or exactly four arguments?)

The previous post had an example from COBOL; C is the same, only in C syntax.
Assembler too. We validate that we got three or five arguments (note there's
an initial, required argument).

Finally: there are some differences in the Enterprise
PL/I compiler regarding compile time options and
options available for declaring functions and
subroutines so I ask this: is your expectation that
your customers will be running the Enterprise PL/I
compiler or some earlier compiler?

Here's a C prototype, with the serial numbers filed off:

int THEFUNCTION( char *magic,
              char *inputBuffer,
              int  *inputLength,
              ...)




--

Kind regards,

-Steve Comstock
The Trainer's Friend, Inc.

303-355-2752
http://www.trainersfriend.com

* To get a good Return on your Investment, first make an investment!
  + Training your people is an excellent investment

* Try our tool for calculating your Return On Investment
    for training dollars at
  http://www.trainersfriend.com/ROI/roi.html

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@bama.ua.edu with the message: INFO IBM-MAIN

Reply via email to