[Default] On 30 May 2017 12:35:46 -0700, in bit.listserv.ibm-main
[email protected] (Farley, Peter x23353) wrote:

>Scott,
>
>That exchange between John and I (around April 7) was about calling C library 
>functions directly from COBOL.  It works if you use a static call (COBOL 
>literal for the entry point name in UPPER CASE, NODYNAM COBOL compiler option) 
>because the C library function load modules (in CEE.SCEELKED) have an external 
>reference to the LE initialization subroutine CEESG003 which will do C 
>language startup initialization in the enclave.  A dynamic COBOL CALL to a C 
>library function (variable name in the CALL or DYNAM COBOL compiler option) 
>will not work unless you manually use an INCLUDE SYSLIB(CEESG003) link edit 
>control card for your link step to get the C language initialization 
>performed, and include CEE.SCEELKED in the link edit SYSLIB DD.
>
>Your code example below should "just work" in terms of getting the C language 
>initialization done because your C subroutine will have an external reference 
>to CEESG003, but passing strings and integers is trickier, because the C 
>language uses (mostly) "pass by VALUE" instead of the COBOL default of "pass 
>by REFERENCE (i.e., pointers)".  You have to carefully use the BY REFERENCE 
>and BY VALUE attributes for the COBOL USING variables.  Integers (and probably 
>floats/doubles as well) must be BY VALUE.  Any structures or arrays (including 
>strings!) or function pointers must be BY REFERENCE.
>
>COBOL does have PICTURE usage type "Z" for zero-terminated strings, so you 
>don't have to use the STRING verb to construct constant strings with a 
>zero-byte terminator to call C modules.  I haven't experimented with moving 
>"normal" COBOL strings (PIC X) to a PIC Z variable, so I do not know if that 
>would work properly.

Picture type Z is for zero suppression so in a PIC ZZZZZ, if 00000 is
moved to it the result is 5 blanks, if 01234 is moved the result is
blank1234 and if 12345 is moved the result is 12345.  I don't know oof
anyway to specify a zero terminated field.

Clark Morris

>
>HTH
>
>Peter
>
>-----Original Message-----
>From: IBM Mainframe Discussion List [mailto:[email protected]] On 
>Behalf Of scott Ford
>Sent: Tuesday, May 30, 2017 2:27 PM
>To: [email protected]
>Subject: Re: A slight regression
>
>John,
>
>I didnt realize you could call C library functions directly, very cool  , here 
>is what i would like to do:
>
>     FILE SECTION.
>       WORKING-STORAGE SECTION.
>       77 TESTSTR   PIC X(30) VALUE SPACES.
>       77 VAR1      PIC S9(9) BINARY VALUE 5.
>       PROCEDURE DIVISION.
>       0000-MAIN.
>      *     MOVE 1 TO P1.
>      *     DISPLAY 'P1: ' P1
>      *     CALL 'CFUNC' USING P1 RETURNING P2
>      *     DISPLAY 'P1: ' P1
>      *     DISPLAY 'P2: ' P2
>            STRING 'TEST STRING' ,
>               LOW-VALUE
>                DELIMITED BY SIZE INTO TESTSTR
>            DISPLAY 'CALL CENTRY USING: ' TESTSTR
>            CALL 'CENTRY' USING  TESTSTR.
>            GOBACK.
>
><c>
>
>#include <stdio.h>
>#include <stdlib.h>
>#include <string.h>
>void CENTRY(char* mystring)
>{
>  printf("my string: %s \n",mystring);
>}
>
>I am trying to understand how to perform the call and pass a string and or a 
>integer ...
>
>Thanks John..
>
>Regards.
>Scott
>
>On Tue, May 30, 2017 at 2:19 PM, John McKown <[email protected]>
>wrote:
>
>> On Tue, May 30, 2017 at 1:07 PM, scott Ford <[email protected]> wrote:
>>
>> > All:
>> >
>> > I saw a thread between Peter Fairley and John  in April, this year
>> speaking
>> > about a cobol program calling C ..I am in the same board but did not 
>> > see the C code. Can some one help me out and point me to the C 
>> > routine or function ?
>> >
>>
>> ?Minor example at:
>> https://gist.github.com/JohnArchieMckown/5b973d46108bd24e0c6f9233c9617
>> 6b0
>>
>> Calls the C subroutines: cuserid(), strlen(). and sscanf(). I don't 
>> have a C compiler, so I don't have an example of any "user written" C code.
>>
>>
>>
>> >
>> > Thanks and I appreciate it
>> >
>> > --
>> >
>> > *IDMWORKS *
>> >
>> > Scott Ford
>> >
>> > z/OS Dev.
>> >
>>
>>
>> --
>> Windows. A funny name for a operating system that doesn't let you see 
>> anything.
>>
>> Maranatha! <><
>> John McKown
>>

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

Reply via email to