The cdecl modifier can be used to declare a function that uses a C type calling convention. This must be used if you wish to acces functions in an object file generated by a C compiler. It allows you to use the function in your code, and at linking time, you must link the object file containing the C implementation of the function or procedure.
As an example:
program CmodDemo; {$LINKLIB c} Const P : Pchar = 'This is fun !'; Function strlen (P : Pchar) : Longint; cdecl; external; begin Writeln ('Length of (',p,') : ',strlen(p)) end.
When compiling this, and linking to the C-library, you will be able to call the strlen function throughout your program. The external directive tells the compiler that the function resides in an external object filebrary (see 1.8).
Remark The parameters in our declaration of the C function should match exactly the ones in the declaration in C. Since C is case sensitive, this means also that the name of the function must be exactly the same. the Free Pascal compiler will use the name exactly as it is typed in the declaration.