1

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.

1
  • Your function_get_char can't get anything because it returns void and takes in an int because you did not list a type, so if anything the type defaults to int. After that, I'm not sure what you are asking. Commented May 18, 2010 at 22:17

2 Answers 2

4

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};
Sign up to request clarification or add additional context in comments.

1 Comment

It looks like @drigo is attempting currying in C (en.wikipedia.org/wiki/Currying).
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.