C declaration styles
Frank Adams
franka at mmintl.UUCP
Sat Apr 2 01:19:40 AEST 1988
In article <297 at ho7cad.ATT.COM> ekb at ho7cad.ATT.COM (Eric K. Bustad) writes:
>No one else has asked, so I guess that I must reveal my ignorance.
>Can someone explain the meaning of Microsoft's "cdecl" keyword?
Microsoft (and a number of other PC C vendors) supports two subroutine
calling conventions: "C" style and "Pascal" style. The Pascal style
supports interface to Pascal, Fortran, and compiled Basic programs, as well
as OS/2 system functions. The C style supports functions with a variable
number of arguments.
One can use the "pascal" keyword on a function declaration to specify that
it is to be called with the pascal convention. Alternatively, one can use a
compile switch to default all functions to pascal. In this case, it is
necessary to have a keyword to specify that a function is to use the C
convention. "cdecl" is it.
(Some compilers support "fortran" as a synonym for "pascal".)
(For those who care: there are two major differences between the two
conventions. In C style, the calling function removes the arguments from
the stack after the call; in Pascal style, the called function does so
before returning. For C style, the arguments are pushed right to left;
Pascal style is left to right. A minor difference is the way that struct
values longer than 4 bytes are returned: C style is for the called function
to put the result in static storage, and return a pointer to it; Pascal
style is for the calling function to pass an additional argument, the
address where the result is to be put.)
--
Frank Adams ihnp4!philabs!pwa-b!mmintl!franka
Ashton-Tate 52 Oakland Ave North E. Hartford, CT 06108
More information about the Comp.lang.c
mailing list