On 07 Sep 2007, at 12:54, Adriaan van Os wrote:

I am trying to find out whether or not to use an underscore prefix when declaring external C functions in FPC using 'external name xxx'. It looks like on Windows the underscore is not needed, whereas on Mac OS X the underscore is required, even when on both platforms 'nm' reveals that the to-be-linked-in C library has an underscore before the C function names.

Note that the Mac OS X Pascal (Carbon) Interfaces for fpc use the underscore, whereas the same Pascal Interfaces for gpc don't.

Is this just a mess or do I miss the true logic behind it ?

If you declare an external function/procedure as "cdecl", the compiler with /always/ add the necessary C-prefix (if any) to the external name.

The universal interfaces are declared as mwpascal rather than cdecl, and such functions/procedures do not automatically get the C-prefix (although one might argue that it would have been better if they did, and indeed if FPC on all platforms by default prefixed all its symbol names with the same prefix as the main C compiler(s), but the fact is that it doesn't do so today -- but maybe this could be changed now that there still aren't many FPC shared libraries in common use).

To make matters even more interesting (in the Chinese sense), there are also {$mode macpas} interface-only units (i.e., units without an implementation section, like many of the universal interfaces). Because this support was added solely for the purpose of supporting (older versions of) the universal interfaces, in that case any function without an explicitly specified external name also gets the C-prefix added (which does not apply to the universal interfaces units, since all functions/procedures there do have an explicitly specified external name).


Jonas
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to