0

I would like f to point to an array of f_pointer_type. So what did i miss here ? I'm getting an error 'lvalue required as left operand of assignment'. What does it mean ?

#include <stdio.h>
typedef char* (*f_pointer_type)();
char * retHello()
{
    return "hello";
}
int main()
{
    char (* ( *f())[])(); //Declare f to be a pointer to an array of pointers to function that gets nothing and return a char.
    f_pointer_type funcs[3]; //an array of pointers to function that gets nothing and returns a pointer to char
    f = &funcs; //ERROR : lvalue required as left operand of assignment
    return 0;
}
2
  • 1
    Why don't you use typedef in f variable definition? f_pointer_type** f; - Commented Aug 7, 2013 at 11:50
  • I guess f is interpreted as some crazy function forward declaration. Commented Aug 7, 2013 at 11:51

3 Answers 3

3

If you read about the clockwise/spiral rule you will see that f is actually a function returning a pointer to an array of pointers to functions returning char*. In other words it's a function prototype and not a variable declaration.

Try this instead:

f_pointer_type (*f)[];
Sign up to request clarification or add additional context in comments.

Comments

1

An array of function pointers is written as char* (*f[])(). You have the parenthesis wrong.

Though it is of course better to always use typedef as in the f_pointer_type funcs[3] example.

Comments

1

You define f as a function pointer. f is pointer to a function who has void params and return char *

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.