[fpc-pascal] Weird compilation warnings

Sven Barth pascaldragon at googlemail.com
Thu Mar 1 08:09:52 CET 2012


Am 29.02.2012 22:53, schrieb Guillermo Martínez Jiménez:
> Hello,
>
> FPC is returning the "Warning: cdecl’ared functions have no high
> parameter" but I have no idea why.  The documentation just says
> "Functions declared with the cdecl modifier do not pass an extra
> implicit parameter." but the affected functions don't have any "extra
> implicit parameter".
>
> I'm using FPC 2.4.2 (the one that came with Lazarus).
>
> Here you have some sample code:
> ___________________________________
>
> UNIT a...;
> IMPLEMENTATION
>
>    {$MODE FPC}
>    {$PACKRECORDS C}
>    {$LONGSTRINGS ON}
>
> { Next declaration compiles Ok. }
>    PROCEDURE al_draw_ustr (CONST font: ALLEGRO_FONTptr; color:
> ALLEGRO_COLOR; x, y: SINGLE; flags: LONGINT; CONST ustr:
> ALLEGRO_USTRptr); CDECL;
>
> { Next one raises the "WARNING" }
>    FUNCTION al_grab_font_from_bitmap (bmp: ALLEGRO_BITMAPptr; n:
> LONGINT; ranges: ARRAY OF LONGINT): ALLEGRO_FONTptr; CDECL;
> ...

You are passing an open array here. open arrays are realized internally 
by passing a pointer to the start of the array and an (implicit) high 
parameter which lets the compiler deduce the length of the array. This 
is not supported with cdecl or cppdecl. If you want a cdecl function to 
receive an array you should write something like this:

     FUNCTION al_grab_font_from_bitmap (bmp: ALLEGRO_BITMAPptr; n:
  LONGINT; ranges: PLONGINT; len: LONGINT): ALLEGRO_FONTptr; CDECL;

Do you want to provide this functions from inside a DLL? If so you 
should use my above variant, because other languages don't understand 
Pascal's open arrays (because of the implicit high parameter). If you 
only use the function inside your own Pascal code I suggest you to not 
use cdecl functions if it's not really necessary.

Regards,
Sven



More information about the fpc-pascal mailing list