By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,330 Members | 1,647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,330 IT Pros & Developers. It's quick & easy.

Returning a pointer to a function

P: n/a
I'm working on a hash table and came upon a small problem. For a better
explanation I've included an extract of the header file for the hash module:

typedef struct TABLE * TABLE_P;
typedef void* (*APPLY_SINGLE_F)( void * data );
typedef void* (*APPLY_PAIR_F)( void * key, void * value );

/* Allocate memory for the table and initialise it */
TABLE_P table_create();

/* Release memory of the table */
void table_release( TABLE_P *t);

Nov 14 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Thomas Brunko wrote:
.... snip ...
Now I would like to write a function transform:
APPLY_PAIR_F transform( APPLY_SINGLE_F apply );
This function builds from its parameter 'apply' a function that
can be used in the call to 'table_apply'. The result of transform
should be a function, that applies the 'apply' function to the
'value' of a (key->value) pair like this:

void * result_of_transform( void * key, void * value ){
return apply( value );

Of course it would be easier to write a function like
void * table_apply_value( TABE_P table, APPLY_SINGLE_F apply );
which applies 'apply' to the values of the table. But I don't want
to extend the interface of my tables if it's not absolutely

Any suggestions?

Take a look at the implementation of hshwalk in my
package. This allows the user to build just such an apply
operation, and many other things.


Chuck F (cb******** (cb********
Available for consulting/temporary embedded and systems.
<> USE worldnet address!

Nov 14 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.