Using the Headers Preprocessor

Running the Header-to-copy utility from the command line is often most convenient when:

For simple header files it can be more convenient to reference the C header file directly from within your COBOL program and allow the Headers preprocessor to invoke the Header-to-copy utility automatically each time the progam is compiled.

To use the Header-to-copy utility in this way, simply include COPY statements that reference .h files within your COBOL program. There is no restriction on where the COPY statements can appear. In addition, ensure you use the directive PREPROCESS(headers). This can be done most conveniently in a $SET statement as in the following example:

$set preprocess(headers)
 working-storage section.
 01 data-item pic x(9).
     copy "cheader.h".
 01 cobol-b usage btype.
 procedure division.
     copy "cheader2.h".
     move 6 to c-long        of cobol-b
     move 7 to c-int         of cobol-b
     move "Show" to c-char   of cobol-b
     display "C struct= " c-long " " c-int " " c-char  level-78.

where cheader.h contains:

#define b B
int a;
typedef struct btype {
   long c_long;
   char c_char[5];
   int  c_int;
   } b;

cheader2.h contains:

#ifdef b
#define level_78 "C literal"
typedef struct btype {
   signed char c_uchar;
   float  c_float[5];
   } b;

and when run, the program displays:

C struct= +0000000006 +00007 Show C literal