Peter/John: Thanks for the help I got my Cobol call to C working fine...This made my day guys. Much appreciated.
Regards, Scott On Tue, May 30, 2017 at 2:51 PM, Farley, Peter x23353 < [email protected]> 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. > > 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 > > > -- > > > This message and any attachments are intended only for the use of the > addressee and may contain information that is privileged and confidential. > If the reader of the message is not the intended recipient or an authorized > representative of the intended recipient, you are hereby notified that any > dissemination of this communication is strictly prohibited. If you have > received this communication in error, please notify us immediately by > e-mail and delete the message and any attachments from your system. > > > ---------------------------------------------------------------------- > For IBM-MAIN subscribe / signoff / archive access instructions, > send email to [email protected] with the message: INFO IBM-MAIN > -- *IDMWORKS * Scott Ford z/OS Dev. “By elevating a friend or Collegue you elevate yourself, by demeaning a friend or collegue you demean yourself” www.idmworks.com [email protected] Blog: www.idmworks.com/blog *The information contained in this email message and any attachment may be privileged, confidential, proprietary or otherwise protected from disclosure. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution, copying or use of this message and any attachment is strictly prohibited. If you have received this message in error, please notify us immediately by replying to the message and permanently delete it from your computer and destroy any printout thereof.* ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN
