The reason behind this is:

C passes arguments "by value", which means that int arguments like textlen are passed directly as values, not as addresses. You get the value 120 in the address list, pointed to by reg 1, not the address of textlen, which is different from COBOL or FORTRAN etc (COBOL and FORTRAN use "call by reference", by default).

That's why you have to pass the address explicitly, if you want to get values back from your C subroutine.

You can write like this:

 retcode = rxhlicpl (hlicmd, name, namelen, text, &textlen);

no need to define (and use) an explicit pointer.

Take care about namelen, by the way. This will behave the same way.

Different with char arrays; the name of a char array without an index is
equivalent with the address of its first element, so it works with char arrays 
(a.k.a. strings)
WITHOUT the & operand.

HTH, kind regards

Bernd


Am 16.04.2024 um 22:14 schrieb Willy Jensen:
Found it, it was down to C pointers as expected / feared.
This works, note the use of 'textlenp' in the call:

#pragma linkage (rxhlicpl, OS)
main () {
  extern int rxhlicpl();
  int retcode;
  char hlicmd[8];
  char name[61];       /* text + eod  */
  int  *namelenp, namelen;
  char text[121];      /* text + eod  */
  int  *textlenp, textlen;
  int  retval;
-  -  -
  retcode = 0;
  strcpy (hlicmd, "VGET    ");
  strcpy (name, "TESTVAR");
  namelen = 7 ;
  textlen = 120;
  textlenp=&textlen;
  retcode = rxhlicpl (hlicmd, name, namelen, text, textlenp);
  printf("rc is %d, text is %d '%s'\n\n", retcode, textlen, text);

----------------------------------------------------------------------
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