Example 2 - Parameter Passing in C and in COBOL

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

C source:

typedef int (_far _pascal* FARPROC)();
typedef struct tagSEGINFO
{
   UINT offSegment;
   UINT cbSegment;
   UINT flags;
   UINT cbAlloc;
   HGLOBAL h;
   UINT alignShift;
   UINT reserved[2];
} SEGINFO;
typedef SEGINFO _far* LPSEGINFO;
typedef struct tagPOINT
{
   int x;
   int y;
} POINT;
void _far _pascal GetCodeInfo(FARPROC lpProc, SEGINFO _far*
                  <_><_>lpSegInfo);
BOOL _far _pascal PtInRect(const RECT _far*, POINT);
void _far _pascal ClientToScreen(HWND, POINT _far*);

COBOL output:

 01  FARPROC     is typedef  usage proc-pointer.
 01  tagSEGINFO  is typedef.
     02  offsegment     usage uns-int.
     02  cbsegment      usage uns-int.
     02  flags          usage uns-int.
     02  cballoc        usage uns-int.
     02  h              usage uns-int.
     02  alignshift     usage uns-int.
     02  reserved occurs 2    usage uns-int.
 01  SEGINFO     is typedef usage tagseginfo.
 01  LPSEGINFO   is typedef usage data-pointer.
 01  tagPOINT    is typedef.
     02  x              usage int.
     02  y              usage int.
 01  POINT   is typedef usage tagpoint.
 end program "c-typedefs".
 program-id."c-typedefs" is external.
 special-names.
      call-convention pascal-convention-val is pascal-conv.
$set constant GetCodeInfo "GetCodeInfo"
 entry GetCodeInfo pascal-conv using
  by value     proc-pointer
  by reference seginfo
     .
$set constant PtInRect "PtInRect"
 entry PtInRect pascal-conv using
  by reference rect
  by value     point
  returning    int
     .
$set constant ClientToScreen "ClientToScreen"
 entry ClientToScreen pascal-conv using
  by value     uns-int
  by reference point
      .
 end program "c-typedefs".

A parameter of data type POINT is passed both BY VALUE and BY REFERENCE.