Take a closer look.  "@PRINTF4", rather than "printf", is being called by the 
CALLPRTF assembler module.  ("Figure 2. Calling an intermediate C function from 
Assembler OS linkage")

@PRINTF4 (actual name _printf4) is defined later on that page:

/* this example demonstrates C/Assembler ILC */
/* part 3 of 3 (other files are CCNGCA2, CCNGCA4) */
/*******************************************************\
 * This routine is an interface between assembler code  *
 * and the C/C++ library function printf().             *
 * OS linkage will not tolerate C-style variable length *
 * parameter lists, so this routine is specific to a    *
 * formatting string and a single 4-byte substitution   *
 * parameter.  It's specified as an int here.           *
 * This object wil be named @PRINTF4.                   *
/*******************************************************/

#pragma linkage(_printf4,OS) /*function will be called from assembler*/

#include <stdio.h>

#pragma map(_printf4,“@PRINTF4”)

int _printf4(char *str,int i) {

   return printf(str,i);       /* call runtime library function */

}

Because of the linkage pragma that specifies "OS" I imagine that, although the 
C code is defined as "pass by value", the OS linkage overrides it to be passed 
by reference.  Just a guess; I don't have a C compiler.

________________________________
From: IBM Mainframe Discussion List <[email protected]> on behalf of 
Paul Gilmartin <[email protected]>
Sent: Thursday, March 30, 2023 5:23 PM
To: [email protected] <[email protected]>
Subject: Re: ASM call by value

On Thu, 30 Mar 2023 23:39:30 +0200, Bernd Oppolzer wrote:
>
>"call by value" in my understanding means, that values are passed, not
>addressed.
>With the mainframe (or z/OS and CMS) linkage convention, this means,
>that values
>and not addresses are in the reg1 parameter list.
>
What happens if there are more value parameters than the total capacity of 
registers?
(But do I misunderstand?  Is the "reg1 parameter list" not actual registers but 
the
storage addressed by GR1 in the CALL macrlo?  If so, it's no practical limit.)


>see above. Because the values entered into the reg1 list "by value" can
>be negative integers
>(or other types, which need more that 4 bytes), the VL convention cannot
>be used by C callers
>
Hmmm.  In 
<https://www.ibm.com/docs/en/zos/2.5.0?topic=programs-calling-c-code-from-assembler-c-example>
I see:
         EDCPRLG
         LA    1,ADDR_BLK              parameter address block in r1
         L     15,=V(@PRINTF4)         address of routine
         BALR  14,15                   call @PRINTF4
         EDCEPIL
ADDR_BLK DC   A(FMTSTR)                parameter address block with..
         DC   A(X'80000000'+INTVAL)    ..high bit on the last address
*   ...
INTVAL   DC   F'222'            The integer value displayed
*
Isn't the "X'80000000'" setting the VL bit?
(I note that's a CD not an EQU.  But the reg1 PL contains an address not a 
value.)

Again, either the caller or the called routine could be able
to convert addresses to values.

--
gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to