|
From: | Michael Anderson |
Subject: | Re: [open-cobol-list] nested call statements, best practices |
Date: | Tue, 17 Sep 2013 11:33:55 -0500 |
User-agent: | Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130803 Thunderbird/17.0.8 |
But here is a similar example. NOTE: They say in C, that it is impossible to "return" a character string, however you can return a pointer to it. Cobol "APP000.cob" ------------------------------------------------- IDENTIFICATION DIVISION. PROGRAM-ID. 'APP000'. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. DATA DIVISION. WORKING-STORAGE SECTION. 1 Input-number Pic X(18) Value spaces. 1 Output-number Pic 9(18) Value Zero. 1 myint32 Pic s9(9) comp Value 0. 1 mychar32-addrs usage is pointer. Linkage Section. 1 mychar32 Pic X(32) Value spaces. Procedure Division. *> -------------------------------------------------------------- Main-Begin. Display "Enter a number? " with no advancing. Accept Input-number. Move numval(Input-number) to myint32. Move myint32 To Output-number. *> Call to C routine, *> to convert a 32 bit int *> to 32 char string, that represent the binary value of the int. call "itobs32" using by value myint32 returning mychar32-addrs. set address of mychar32 to mychar32-addrs. Display "The binary value of " trim(Output-number) " is: " mychar32. Stop run. C Routine itobs32.c ----------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <string.h> /* itobs32: Converts a 32-bit Integer to a binary string. Each byte of the binary string will contain a '1' or '0', representing the bit values in the integer. -----------------------------------------------------------*/ char *itobs32(int b) { char outstr[33]; // the binary string that will contain the 1's and 0's int i; for (i = 31; i >= 0; --i) { outstr[i] = (b & (1<<0)) ? '1' : '0'; b = b >> 1; } outstr[32]='\0'; return strdup(outstr); // copy the string and return the pointer to it. } Compile..... cobc -x -free -ffunctions-all APP000.cob itobs32.c On 09/17/2013 08:30 AM, Patrick wrote:
Hi Everyone I was thinking of writing some utility programs to convert values back and forth from C. I want to write code like this: CALL 'someCfunction' USING BY CONTENT CALL "convert-string' USING BY CONTENT arg1 RETURNING foo END-CALL I could probably figure this out but but my fear is that it would be less then optimal use of what is available. Could anyone point me to an example of the correct way to do this? I have not come across one. Thanks ------------------------------------------------------------------------------ LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99! 1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint 2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk _______________________________________________ open-cobol-list mailing list address@hidden https://lists.sourceforge.net/lists/listinfo/open-cobol-list
[Prev in Thread] | Current Thread | [Next in Thread] |