On 14 Mar 2005 at 3:48, willett wrote:
Frank,
Thanks very much for the helpful info on location of fpc copying rights and on location of current version. (I don't know how they find stuff in the fpc archives, packages, sources...) I'm very glad to now be working from the most recent source version.
One construction I'm not sure on translation of is:
function beep:longint; cdecl;external libncurses; function can_change_color:bool; cdecl;external libncurses; function cbreak:longint; cdecl;external libncurses;
The fpc "cdecl;' makes the calling sequence of Pascal match that of c. (see the table from FPC manual at end of this email; its a graphic file, sorry, I couldn't get a good text cut.) It appears 'cdecl' is the default for gpc (true?), thus, for gpc I think these could be declared, somewhat like the external variables were, as, e.g.:
function beep:longint; external libncurses;
However, gpc does not like the library name after external and gives the error
... error: syntax error before `libncurses'
That is Delphi and BP syntax. GPC does not support that syntax.
So I can resolve the syntax error by shortening it to just:
function beep:longint; external;
Yes. Better still is: function beep:longint; external name 'beep';
But I'm left wondering why the prior author thought he needed to specify the libncurses...
Because that is correct Delphi syntax.
So, two questions:
- Am I correct in assuming that no parallel to FPC's 'cdecl' is needed for calls from GPC to C?
Who knows? But this should solve your problem with cdecl: {$ifdef __GPC__} {$define cdecl attribute(cdecl)} {$endif}
- Is there a way to specify the library source for a function call, as it is done with external variables? Or, conversely, can I assume that this isn't needed?
Not needed. Simply do this: {$L ncurses}
What you are likely to have problems with (in future GPC versions) is that, you should use "external name 'foo'" instead of just "external". If you don't specify the name of the external symbol, GPC allocates a default. The warnings indicate that the default may be problematic, and that there will be no warnings in future versions.
BTW: I have a version of ncurses.pp that compiles under GPC. But there are linker problems, both under Windows and Linux when you try to comple a test program. It is the same one: "undefined reference to `_acs_map'".
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/