John, Not "nutso" at all, just very cool.
I notice you are using "static" calls (quoted literal program names) in upper case. Does that mean that you statically link the C subroutines with your program? Does it require using any non-default compiler options? Assuming you are using COBOL V4.2 or earlier, do you have to use PDSE's for the load modules because of the C subroutines? I am quite excited if this is all I have to do to use C library routines, but static links make me uneasy, especially for system-level runtime code like the C library functions. Peter -----Original Message----- From: IBM Mainframe Discussion List [mailto:[email protected]] On Behalf Of John McKown Sent: Thursday, April 06, 2017 1:52 PM To: [email protected] Subject: Opinion: Using C "standard library" routines in COBOL. This is just a curiosity poll on my part. I'm wondering if anyone out there has ever really used any C standard library routines (versus user written code) in a COBOL program. I know that many may wonder "Why? What do I get out of it." IMO, there are some useful routines in the standard C library which could be used in COBOL. One in particular which shows up quickly is the C language "cuserid()" function. It will return the RACF id under which the program is running. Now, since cuserid() plops a LOW-VALUE as an end-of-string delimiter, that needs to be taken into consideration. Something like the following worked for me: 01 USERID-PLUS-1 05 USERID PIC X(8). 05 FILLER PIC X. 01 CUSERID-POINTER POINTER. CALL 'CUSERID' USING USERID-PLUS-1. as did CALL 'CUSERID' USING USERID-PLUS-1 RETURNING CUSERID-POINTER. But this latter is unnecessary since the ID will be in USERID. But it might have a LOW-VALUE, so it is better to do a MOVE SPACES TO USERID before the CALL and a INSPECT USERID REPLACING LOW-VALUES BY SPACES after the call. There are a lot more "interesting" C library functions which might be useful. Such as the regular expression library for advanced text scanning (OK, not a big COBOL thing). How about __get_cpuid() to get the CPU id of the processor you're running on? DES encryption of data? The sprintf() function to create a nicely formatted human readable message easily (not a lot of space padding) although STRING might do this as well. On older compilers, use the "calloc()" and "malloc()" function to get dynamic storage areas to map with the LINKAGE SECTION. How about using "popen()" to fire up a UNIX process to do some work for you? Well, I'm going nutso again. -- 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
