[fpc-pascal] Documentation or compiler bug?
Michael Van Canneyt
michael at freepascal.org
Sat Jul 8 10:57:10 CEST 2023
On Sat, 8 Jul 2023, Hairy Pixels via fpc-pascal wrote:
> In fact I filed a bug today which was related. Notice how I didn't use cdecl in the program but another user tried to compile and had problems with cdecl also.
>
> https://gitlab.com/freepascal.org/fpc/source/-/issues/40342 <https://gitlab.com/freepascal.org/fpc/source/-/issues/40342#note_1462402401>
>
> Basically this program:
>
> {$mode objfpc}
>
> program test;
>
> function printf(format: PChar): Integer; external; cdecl; varargs;
You must put the cdecl (which is the calling convention) before the external:
{$linklib c}
function printf(format: PChar): Integer; cdecl; external; varargs;
begin
printf('%d is the answer'#10,42)
end.
Will work and will print
42 is the answer
Michael.
More information about the fpc-pascal
mailing list