例 - C 呼び出し規則の翻訳

Header-to-copy ユーティリティが C ソース コード内の呼び出し規則を等価な COBOL COPY ファイル形式に翻訳する例を次に示します。

C のソース

typedef HINSTANCE HMODULE;
DWORD _far _pascal GetVersion(void);
UINT _far _pascal GetFreeSystemResources(UINT);
#define GFSR_SYSTEMRESOURCES 0x0000
BOOL _far _pascal SetWinDebugInfo(const WINDEBUGINFO _far*
<_><_>lpwdi);
void _far _cdecl DebugOutput(UINT flags, LPCSTR lpsz, ...);
#define WDI_OPTIONS 0x0001

生成される COBOL コード

 01  HMODULE    is typedef usage uns-int.
 end program "c-typedefs".
 program-id."c-typedefs" is external.
 special-names.
     call-convention pascal-convention-val is pascal-conv.
$set constant GetVersion "GetVersion"
 entry GetVersion pascal-conv
  returning   uns-long
     .
$set constant GetFreeSystemResources "GetFreeSystemResources"
 entry GetFreeSystemResources pascal-conv using
  by value     uns-int
  returning    uns-int
     .
 end program "c-typedefs".
 program-id."c-typedefs" is external.
 special-names.
     call-convention pascal-convention-val is pascal-conv.
 78  GFSR-SYSTEMRESOURCES     value h"0000".
 end program "c-typedefs".
 program-id."c-typedefs" is external.
 special-names.
     call-convention pascal-convention-val is pascal-conv.
$set constant SetWinDebugInfo "SetWinDebugInfo"
 entry SetWinDebugInfo pascal-conv using
  by reference windebuginfo
  returning    int
     .
 end program "c-typedefs".
 program-id."c-typedefs" is external.
 special-names.
     call-convention cdecl-convention-val is cdecl-conv.
$set constant DebugOutput "DebugOutput"
 entry DebugOutput cdecl-conv using
  by value     uns-int
  by reference any
  by value     any
     .
 end program "c-typedefs".
 program-id."c-typedefs" is external.
 special-names.
     call-convention cdecl-convention-val is cdecl-conv.
 78  WDI-OPTIONS    value h"0001".
 end program "c-typedefs".

H2cpy による COBOL コードの生成は、標準呼び出し規則を使用するデフォルトの外部プログラム、c_typedefs 内から開始されています。GetVersion ルーチンでは Pascal の呼び出し規則が使用されるため、H2cpy は手続き部の ENTRY 文を含む新しい外部プログラムのヘッダーを生成しています。GetFreeSystemResources ルーチンは同じ Pascal の呼び出し規則を使用します。そのため、ここでは新しいプログラム ヘッダーは生成されず、2 つ目の ENTRY 文が生成されています。続いて、データ部内に 78 レベル項目を 1 つ生成する必要があるため、H2cpy は新しいプログラム ヘッダーを生成しています。さらに、DebugOutput ルーチンでは cdecl 呼び出し規則が使用されるため、プログラム ヘッダーをもう 1 つ生成しています。