Hello,
I am currently reading the Reference Manual and executing the examples that are presented there. On page 196, there is an example to show how to use "array of const" with a C function. The program is as follows:
program testaocc;
{$mode objfpc}
Const
P : PChar = ’example’;
Fmt : PChar =
’This %s uses printf to print numbers (%d) and strings.’#10;
// Declaration of standard C function printf:
procedure printf (fm : pchar; args : array of const);cdecl; external ’c’;
begin
printf(Fmt,[P,123]);
end.
The program compiles but won't load/run because "c.dll" is missing. The complaint that c.dll is missing makes sense but, something tells me the example was meant to work and I may be missing something.
My question is: what changes are needed in the above example to make it run ?
NOTE: I can get the example to work by modifying the printf declaration to be as follows:
const
user32 = 'user32.dll';
procedure printf (Output,
Format : pchar; args : array of const); cdecl;
external user32 name 'wsprintfA';
but that seems too far from the original declaration to believe that was its original intent.
From what I've learned about FPC so far, I am under the impression that it statically links with a C library (I could easily be wrong about that). Was the declaration in the example meant to provide access to the printf function which may be included in that library ? (I'm just guessing... just wondering what the intent of the declaration in the example is/was)
Thank you for your help.