Next: , Up: Windows Calling Conventions   [Contents][Index]


7.4.7.2 C Calling Convention

This is the default calling convention used when interfacing to C/C++ routines compiled with either gcc or Microsoft Visual C++.

In the C calling convention subprogram parameters are pushed on the stack by the caller from right to left. The caller itself is in charge of cleaning up the stack after the call. In addition, the name of a routine with C calling convention is mangled by adding a leading underscore.

The name to use on the Ada side when importing (or exporting) a routine with C calling convention is the name of the routine. For instance the C function:

int get_val (long);

should be imported from Ada as follows:

function Get_Val (V : Interfaces.C.long) return Interfaces.C.int;
pragma Import (C, Get_Val, External_Name => "get_val");

Note that in this particular case the External_Name parameter could have been omitted since, when missing, this parameter is taken to be the name of the Ada entity in lower case. When the Link_Name parameter is missing, as in the above example, this parameter is set to be the External_Name with a leading underscore.

When importing a variable defined in C, you should always use the C calling convention unless the object containing the variable is part of a DLL (in which case you should use the Stdcall calling convention, Stdcall Calling Convention).