Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-02

Weird compilation warnings

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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;
...
IMPLEMENTATION
  PROCEDURE al_draw_ustr (CONST font: ALLEGRO_FONTptr; color:
ALLEGRO_COLOR; x, y: SINGLE; flags: LONGINT; CONST ustr:
ALLEGRO_USTRptr); CDECL;
  EXTERNAL ALLEGRO_FONT_LIB_NAME;
  FUNCTION al_grab_font_from_bitmap (bmp: ALLEGRO_BITMAPptr; n:
LONGINT; ranges: ARRAY OF LONGINT): ALLEGRO_FONTptr; CDECL;
  EXTERNAL ALLEGRO_FONT_LIB_NAME;
...
END.
_____________________________

Guillermo "Ñuño" Martínez

Sven Barth
to Guillermo Martínez Jiménez
Guillermo Martínez Jiménez wrote 29 lines
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

Guillermo Martínez Jiménez

Oh, I see. It has sense. The "extra implicit parameter" part confused me because I didn't use OOP in that project.

Thank you :)

2012/3/1 :

Show quoted text 51 lines
From: Sven Barth Subject: Re: [fpc-pascal] Weird compilation warnings 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