When H2INC converts C function prototypes into MASM function prototypes, the elements of the C syntax are converted into the corresponding elements of the MASM syntax.
The syntax of a C function prototype is
[[storage]] [[distance]] [[ret_type]] [[langtype]]label ( [[parmlist]] )
In C syntax, storage can be STATIC or EXTERN. H2INC does not translate static function prototypes because static functions are visible only within the current source module, and standard include files do not contain executable code.
Summary: Procedures for returning values depend on the langtype specified.
In C, the ret_type is the data type of the return value. Because the MASM PROTO directive does not specify how to handle return values, H2INC does not translate the return type. However, H2INC checks the langtype specified in the C prototype to determine how particular languages return the value—through the stack or through registers.
For the Pascal, FORTRAN, or Basic langtype specifications, H2INC appends an additional parameter to the argument list if the return type is longer than four bytes. This parameter is always a near pointer with the type of the return value. If the value of the return value type is not supported, this parameter is an untyped near pointer.
For the _cdecl langtype specification in the C prototype, all returned data is passed in registers (AX or AX plus DX). There is no restriction on the return type. Additional parameters are not necessary.
The langtype represents the naming and passing conventions for a language type. H2INC accepts the following C language types and converts them to their corresponding MASM language types:
C Language Type | MASM Language Type | |
_cdecl | C | |
_fortran | FORTRAN | |
_pascal | PASCAL | |
_stdcall | STDCALL | |
_syscall | SYSCALL |
H2INC explicitly includes the langtype in every function prototype. If no language type is specified in the .H file prototype, the default language is _cdecl (unless the default is overridden by the /Gc command-line option).
In the MASM prototype syntax, the label is the name of the function or procedure.
If you select the /Mn option, H2INC specifies the distance of the function (near or far), whether or not the C prototype specifies the distance. If /Mn is not set, H2INC specifies the distance only when it is different from the default distance specified by the memory model.
If the C prototype's parameter list ends with a comma plus an ellipsis (, ...), the function can accept a variable number of arguments. H2INC converts this to the MASM form: a comma followed by the :VARARG keyword (, :VARARG) appended to the last parameter.
H2INC does not translate _fastcall functions. Functions explicitly declared _fastcall (or invoking H2INC with the /Gr option) generate a warning indicating that the function declaration has been ignored.
The following examples show how the preceding rules control the conversion of C prototypes to MASM prototypes (when the memory model default is small). The example function is my_func. The TYPEDEF generated by H2INC for the PROTO is given along with the PROTO statement.
/* C prototype */
my_func (float fNum, unsigned int x);
; MASM TYPEDEF
@proto_0 TYPEDEF PROTO C :REAL4, :WORD
; MASM prototype
my_func PROTO @proto_0
/* C prototype */
extern my_func1 (char *argv[]);
; MASM TYPEDEF
@proto_1 TYPEDEF PROTO C :PTR PTR SBYTE
; MASM prototype
my_func1 PROTO @proto_1
/* C prototype */
struct vconfig _far * _far pascal my_func2 (int, scri );
; MASM TYPEDEF
@proto_2 TYPEDEF PROTO FAR PASCAL :SWORD, :scri
; MASM prototype
my_func2 PROTO @proto_2
/* C prototype */
long pascal my_func3 (double y, struct vconfig vc);
; MASM TYPEDEF
@proto_3 TYPEDEF PROTO PASCAL :REAL8, :vconfig
; MASM prototype
my_func3 PROTO @proto_3
/* C prototype */
void _far _cdecl myfunc4 ( char _huge *, short);
; MASM TYPEDEF
@proto_4 TYPEDEF PROTO FAR C :FAR PTR SBYTE, :SWORD
; MASM prototype
myfunc4 PROTO @proto_4
/* C prototype */
short my_func5 (void *);
; MASM TYPEDEF
@proto_5 TYPEDEF PROTO C :PTR
; MASM prototype
my_func5 PROTO @proto_5
/* C prototype */
char my_func6 (int, ...);
; MASM TYPEDEF
@proto_6 TYPEDEF PROTO C :SWORD, :VARARG
; MASM prototype
my_func6 PROTO @proto_6
/* C prototype */
typedef char * ptrchar;
ptrchar _cdecl my_func7 (char *);
; MASM TYPEDEF
@proto_7 TYPEDEF PROTO C :PTR SBYTE
; MASM prototype
my_func7 PROTO @proto_7
See Section 7.3.6, “Declaring Procedure Prototypes,” for more information on prototypes and Chapter 20, “Mixed-Language Programming,” for information on calling conventions and mixed-language programs.