Previous Topic Next topic Print topic


Example 1 - 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 unsigned char BYTE;
typedef char _far* LPSTR;
typedef int HFILE;
typedef Boolean (*XtFilePredicate)( /* String filename */ );
BYTE _far _pascal GetTempDrive(char);
long _far _pascal _llseek(HFILE, long, int);
long _far _pascal _hwrite(HFILE, const void _huge*, long);
LPSTR _far _pascal AnsiLower(LPSTR);
void _far _pascal Throw(const int _far*, int);
extern_pascal String XtFindFile( 
   CONST String    /* path */,
   Substitution    /* substitutions */,
   Cardinal    /* num_substitutions */,
   XtFilePredicate  /* predicate */
);

COBOL output:

 01  BYTE             is typedef usage uns-char.
 01  LPSTR            is typedef usage data-pointer.
 01  HFILE            is typedef  usage int.
 01  XtFilePredicate  is typedef usage proc-pointer.
 end program "c-typedefs".
 program-id."c-typedefs" is external.
 special-names.
     call-convention pascal-convention-val is pascal-conv.
$set constant GetTempDrive "GetTempDrive"
 entry GetTempDrive pascal-conv using 
  by value     char
  returning    uns-char
     .
$set constant 1-llseek "_llseek"
 entry 1-llseek pascal-conv using
  by value     int
  by value     long
  by value     int
  returning    long
     .
$set constant 1-hwrite "_hwrite"
 entry 1-hwrite pascal-conv using
  by value     int
  by value     data-pointer
  by value     long
  returning    long
     .
$set constant AnsiLower "AnsiLower"
 entry AnsiLower pascal-conv using
  by reference any
  returning    data-pointer
.
$set constant Throw "Throw"
 entry Throw pascal-conv using
  by reference int
  by value     int
.
 end program "c-typedefs".
 program-id."c-typedefs" is external.
 special-names.
     call-convention default-convention-val is default-conv.
 end program "c-typedefs".
 program-id."c-typedefs" is external.
 special-names.
     call-convention default-convention-val is default-conv.
$set constant XtFindFile "XtFindFile"
 entry XtFindFile default-conv using
  by reference any
  by value     data-pointer
  by value     uns-int
  by value     proc-pointer
  returning    data-pointer.
     .
 end program "c-typedefs".

Notice in the routine _hwrite that a pointer to a void generates a data pointer passed by value. However, in the routine AnsiLower the type LPSTR which is a pointer to a character generates a BY REFERENCE clause with any parameter being allowed. A char would be too restrictive as normally any COBOL alphabetic item would be suitable. For this reason H2cpy generates any.

In the routine Throw, we have an int passed both BY VALUE and BY REFERENCE. In the routine XtFindFile, we pass a procedure pointer BY VALUE.

Previous Topic Next topic Print topic