Example - Translating Named Declarations

The following example shows how the Header-to-copy utility translates named declarations in C source code to their equivalent COBOL copyfile form.

C source:

typedef struct fsid { long val[2]; } fsid_t;
typedef unsigned long ino_t;  /* inode number (filesystem) */
typedef unsigned int  uint_t;
#define FHSIZE        32
#define MAXFIDSZ     (FHSIZE - sizeof(fsid_t) - sizeof(uint_t))
struct fileid {  /* this is for servers only! */
       uint_t  fid_len;
       ino_tfid_ino;
       uint_t  fid_gen;
       char fid_x[MAXFIDSZ - (sizeof(ino_t) + 2) - sizeof(uint_t)];  
};

COBOL output:

 01  fsid           is typedef.
     02  val occurs 2     usage long.
 01  fsid-t         is typedef usage fsid.
 01  ino-t          is typedef usage uns-long.
 01  uint-t         is typedef usage uns-int.
 78  FHSIZE         value 32.
 78  MAXFIDSZ       value 28.
 01  fileid         is typedef.
     02  fid-len          usage uns-int.
     02  filler       pic x(2).
     02  fid-ino          usage uns-long.
     02  fid-gen          usage uns-int.
     02  fid-x        pic x(14).

H2cpy ensures the correct alignment of the field fid-ino (which is a long, alignment 4) by inserting a two-byte FILLER item after the two-byte fid-len field.

The correct alignment is subject to the -e and -a options as well as the #pragma pack directive.