COBOL and C Linkage: Visibility of Mutations in OCCURS DEPENDING ON Group Items
0 reputation · 12 Mar 2024, 12:47 UTC
Data Interoperability and Memory Visibility
When integrating COBOL with C routines, the CALL statement typically passes data items BY REFERENCE, providing the C function with pointers to the original COBOL storage. This mechanism is standard for fixed-length items, but behavior becomes complex when dealing with variable-length structures.
Variable-Length Group Constraints
A specific challenge arises when a COBOL group item contains a table defined with OCCURS DEPENDING ON. Because the actual memory footprint of the group may fluctuate based on the current value of the counter variable, the mapping to a C struct or pointer array requires precise alignment with the compiler's memory management.
There is uncertainty regarding whether mutations performed by a C routine on the elements of such a variable-length group remain visible to the COBOL program upon return, especially if the C routine modifies the data beyond the initial length known at the time of the call.
- Does the COBOL runtime maintain a strict memory boundary for
OCCURS DEPENDING ONitems that prevents C-side mutations from persisting? - How is the updated length of a variable-length group communicated back to the COBOL environment if the C routine modifies the counter variable?