OpenCOBOL Forum Index OpenCOBOL
calling cobol para from C | Register To Post |
| Threaded | Newest First | Previous Topic | Next Topic | Bottom |
| Poster | Thread |
|---|---|
| sajjar | Posted on: 2011/6/1 6:12 |
Quite a regular ![]() ![]() Joined: 2010/6/15 From: Chennai, India Posts: 44 |
calling cobol para from C Hi, I want to call a COBOL paragraph from a C program; I'm making use of PROCEDURE-POINTER and ENTRY stmt to get the para Entry pointer and passing this to a C program where I'm doing function call based on this pointer.
I'm getting "Attempt to reference unallocated memory" error. Could anyone please help me. I'm using Ubuntu 10.04 OS. HANDCOND.CBL CPROG.c |
| ctimmer | Posted on: 2011/6/1 14:59 |
Not too shy to talk ![]() ![]() Joined: 2006/10/20 From: Big Lake, Alaska Posts: 22 |
Re: calling cobol para from C CALL 'CPROG' USING HAND-COND-ADDR.
I would try changing this to call by-value. Curt |
| btiffin | Posted on: 2011/6/2 2:21 |
Home away from home ![]() ![]() Joined: 2008/6/7 From: CANADA Posts: 1196 |
Re: calling cobol para from C sajjar; Ditto-ing Curt.
See http://www.opencobol.org/modules/newbb/viewtopic.php?topic_id=1320&forum=1#forumpost6681 for an explanation of why. Cheers, Brian |
| sajjar | Posted on: 2011/6/2 3:24 |
Quite a regular ![]() ![]() Joined: 2010/6/15 From: Chennai, India Posts: 44 |
Re: calling cobol para from C That magic word BY VALUE worked magically
Thanks for the help.However, the expected behavior I could not get it. I was expecting after the CALL, the cobol program should stop since the 999-EXIT-PROC para is having GOBACK stmt; but control came back to cobol program and continued till STOP RUN stmt. Is there anyway I could get my expected behavior ?. Thanks, Sajjar. |
| btiffin | Posted on: 2011/6/2 13:54 |
Home away from home ![]() ![]() Joined: 2008/6/7 From: CANADA Posts: 1196 |
Re: calling cobol para from C Couple of things for that then Sajjar.
Take a look at Gary's programming guide. CALL has an ON EXCEPTION clause. That is what will fire if the CALL itself has trouble. The RETURN-CODE is actually the result of the sub program, when the CALL itself has already 'succeeded'. Next; GOBACK is, by definition, smart and 'does the right thing' and won't terminate a program run unless it occurs as the last of the call stack when it should return control to the operating system. If you want a subprogram to terminate the run unit as a whole, use STOP RUN. (And for fun, look at EXIT PROGRAM too). Gary's guide does a pretty good job of explaining all of the ins and outs of program flow rules. From C you can call exit(status) which, by definition, unwinds the return stack and returns control (with the int status as it's result code) to the OS regardless of how deeply nested. That exit(status) is how STOP RUN (after proper COBOL cleanup) actually works as well. You can see the details in the OpenCOBOL sources in libcob/common.c in the function cob_stop_run. This is versus cobtidy which properly cleans up COBOL but does NOT terminate the process. Cheers, Brian |
| sajjar | Posted on: 2011/6/2 15:45 |
Quite a regular ![]() ![]() Joined: 2010/6/15 From: Chennai, India Posts: 44 |
Re: calling cobol para from C Thank you brian for the educative explanation. Now, I understood something on control flow; with this I shall design progs accordingly.
Regards, Sajjar. |
| Threaded | Newest First | Previous Topic | Next Topic | Top |
| Register To Post | |








Thanks for the help.