The following example shows how the Header-to-copy utility translates enumerator declarations in C source code to their equivalent COBOL copyfile form.
C source:
enum input_type { GPICK = 0x0001, GANK= 0x0002, GPFK = 0x0004, FP_NOINBUF = 0x10000, FP_WTMAX = 0x20000 }; typedef struct qqel { /* queue element*/ enum input_type type; /* enum input_type value */ int time; /* timestamp */ struct { unsigned bad_data :1; /* extra data io failed */ unsigned no_data :1; /* queue empty (for K_POLL) */ unsigned reserved :6; /* reserved */ char rsvd[3]; /* reserved */ } flags; int data_len; /* length of appended data */ } q_qel;
COBOL output:
01 input-type is typedef usage uns-int. 78 gpick value 1. 78 gank value 2. 78 gpfk value 4. 78 fp-noinbuf value 65536. 78 fp-wtmax value 131072. 01 qqel is typedef. 02 type usage input-type. 02 time usage int. 02 flags. 03 bad-data. 04 bad-data usage uns-int. *>> 1 Bit 03 filler redefines bad-data. 04 no-data usage uns-int. *>> 1 Bit 03 filler redefines bad-data. 04 reserved usage uns-int. *>> 6 Bits 03 rsvd pic x(3). 03 filler pic x(1). 02 data-len usage int. 01 q-qel is typedef usage qqel.
The field rsvd is three bytes long. An assumption has been made that the preceding eight bits allocate one byte of storage. In fact, the ANSI C standard says that bitfields are within an integer and so a 16-bit area will be allocated, requiring H2cpy to add a one-byte padding item on the end.