C Calling Convention (GNAT User’s Guide for Native Platforms)

#### 7.4.8.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 example you should import the C function:

>     int get_val (long);

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, you could have omitted the `External_Name` parameter since, when missing, this parameter is set to 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 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).