C Function Parameters

Stewart Gordon smjg_1998 at yahoo.com
Tue Sep 5 15:39:27 PDT 2006


Tyro wrote:
> Could someone please tell me if I'm reading the following correctly
> 
>     int myfunc(MyStruct *ms, void * (*allocF)(size_t s))
> 
> The second parameter above [void * (*allocF)(size_t s)], is a pointer to 
> a function that accepts a size_t parameter and returns a void pointer? 

Yes.

<snip>
>     2) Is [void function(size_t s) allocF] a suitable replacement

No.  However, this is:

     int myfunc(MyStruct* ms, void* function(size_t s) allocF)

I always use the D function/delegate notation.  Much easier to read than 
the C notation.  Note also that the '*' has been attached to the type, 
which is more logical in D.

> or would it be better to use a delegate?

Whether you should use function or delegate depends on what you're going 
to pass in.

function - module level functions or static member functions
delegate - member functions acting on a specific object, or nested functions

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-learn mailing list