Header-to-copy ユーティリティが C ソース コード内の列挙宣言を等価な COBOL COPY ファイル形式に翻訳する例を次に示します。
C のソース
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 コード
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.
rsvd は 3 バイト長の項目です。直前の 8 ビットで 1 バイトの記憶域が割り当てられることを前提としていましたが、ANSI C ではビットフィールドに整数型の項目を充てるように定義されているため、実際には 16 ビットの領域が割り当てられます。したがって、H2cpy は末尾に空白詰め用の 1 バイト項目を追加する必要があります。