Microsoft KB Archive/99487

= Argument Orders for CDECL and PASCAL Functions in MASM =

Article ID: 99487

Article Last Modified on 10/31/2006



This article was previously published under Q99487



SUMMARY
Making Macro Assembler (MASM) calls to C functions is straightforward if you keep in mind the order of the arguments. How the arguments are pushed for the two most commonly used types of functions, CDECL and PASCAL, is described below.

The LAN Manager APIs all use FAR PASCAL calling conventions.

ARGUMENTS FOR CDECL
int x,y;              /* C Lang call */ int min(x,y);

push  y             /* MASM call */ push  x             /* Note: arguments are pushed from right

/* to left */

call  _min          /* On return from the function, you must

/* reset your */

add   sp,4          /* stack. That is: add sp,(total size of

/* arguments passed) */

ARGUMENTS FOR PASCAL
(Use for all LAN Manager APIs) int x,y; int PASCAL max(x,y);  /* C Lang call */

push x                /* MASM call */ push y                /* Note: arguments are pushed from left

/* to right */

call _max             /* On return from PASCAL function, no

/* additional work is required. The /* function itself does a RET X, where x                      /* is the size of the arguments passed.*/ You also must use the H2INC utility to convert any header files that contain data definitions. The H2INC documentation (&quot;Programmer's Guide,&quot; Chapter 14) discusses ways to convert function definitions so that MASM can understand them. You can also convert a C file to MASM in order to check its syntax with the following command:   cl -c -Fa -Fs file.c

