Daniel Levite ([log in to unmask]) wrote: : does anyone know if you can put a C routine in an XL that can then be : called from COBOL? : and can you point me in the direction on where to learn how to do : this...thaks For sake of discussion, I'll assume you are talking about COBOL II/iX and C/iX on MPE/iX 5.0 or later, and that you have the following manuals. 1. HP COBOL II/XL Reference Manual, part number 31500-90001, July 1991 edition. 2. HP COBOL II/XL Programmer's Guide, part number 31500-90002, July 1991 edition. 3. HP C/iX Reference Manual, part number 31506-90005, June 1992 edition. 4. HP C Programmer's Guide, part number 92434-90002, August 1992 edition. 5. HP C/iX Library Reference Manual, part number 30026-90001, October 1992 edition. The answer is yes, a COBOL program can call a C function that resides in an XL. It can be a lot of fun, if you like that sort of thing. To some extent, it is even supported. For some actual sample code showing COBOL calling C, see pages 4-22 through 4-24 of the COBOL programmer's guide. There are several things in particular that you need to be aware of. 1. You need to understand how both languages store their various data types and pass/receive parameters. Pay attention to storage format and alignment. For COBOL, pay attention to the USAGE clause (reference manual, pp. 7-64 through 7-68) and the alignment rules (page H-22). If you want to pass pointers, you might need the .LOC. pseudo-intrinsic (p. 11-20). And if you want to pass by value, you'll need backslashes in the CALL statement (p. 11-15). Then there's the GIVING phrase if you want to receive a function return (p. 11-24). For C, data types and alignment are documented in the reference manual (Chapter 9) and the programmer's guide (Chapter 2). 2. The C function may not work right unless you turn off COBOL traps. For a discussion of the COBOL trap mechanism and how it relates to other languages, read pp. H-33 through H-38 of the COBOL reference manual. Be sure to turn COBOL traps back on as soon as you return from the C function. 3. If the C function does any output using the C library, remember that buffered output won't be automatically flushed when the program terminates, since the outer block won't be in C. You will want to explicitly flush the output, close the files, or use unbuffered I-O. There are some other potential pitfalls, but this should get you started. Have fun! Walter Murray Hewlett-Packard Support Technology Lab