tags:

views:

115

answers:

2

See, I have two functions, one to get a char, and other to put a char like this.

void function_get_char (input);
void function_put_char (output);

I have a function pointer to these functions like this.

void (*function_operators[])(input_or_output) = {function_get_char, function_put_char};

I need of, when I'll call my function_operator, I want to don't need to specify if I want to get it in of output or of my input.

Do I need to build my function pointer like this?

void (*function_operators[])(input_or_output) = {function_get_char(input), function_put_char(output)};

How can I do it? Thanks in advance.

NOTE

input or output parameter, is not run_time parameter.

A: 

You will have to create a function with no arguments which wraps the call to the function with an argument. If you need to do this at runtime, then look at (one of the definitions of) thunk or trampolines.

Pete Kirkham
+3  A: 

I'm not really sure what you want to do, but if you want to fix input and output to some predefined value (since you say they are not runtime parameters), the easiest solution should be to write some wrapper functions that call the "real" functions with the correct parameters. For example:

void fixed_get_char(void) { function_get_char(input); }
void fixed_put_char(void) { function_put_char(output); }

void (*function_operators[])(void) = {fixed_get_char, fixed_put_char};
sth
It looks like @drigo is attempting currying in C (http://en.wikipedia.org/wiki/Currying).
Judge Maygarden