How to create C function pointers

Stewart Gordon smjg_1998 at yahoo.com
Tue Sep 19 14:13:01 PDT 2006


Don Clugston wrote:
> Mildred wrote:
>> Hi,
>>
>> So, I need to have C functions pointers but I don't know how to declare 
>> them correctly :
> 
> It's easiest to typedef them; the typedef picks up the extern(C).

Or alias them.

>> module test;
>>
>> extern(C){
>>     int c_function(int param){
>>         return param;
>>     }
>> }
> 
> extern (C) {
>   typedef int function(int) CFuncPtr;
> }
<snip>

I see.  So

     extern (C) int function(int) ptr = &c_function;

merely gives the symbol ptr C linkage, and doesn't affect the linkage of 
the function involved?

There ought to be a way of giving function pointer types linkage 
attributes inline.  Maybe

     int extern (C) function(int) ptr = &c_function;

or something...?

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- 
PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.



More information about the Digitalmars-d mailing list