Search code examples
gcccompilationlvaluerequired

GCC error when compiling: "lvalue required as left operand of assignment" with function pointer


I have a C code which records a procedure address in an array

void* lpProcAddress[5];

typedef unsigned long (*MyFunction_TYPE) (void*);
#define MyFunctionInArray ( (MyFunction_TYPE) lpProcAddress[0] )

unsigned long AnyFunction ( void* lpPointerToAny )
{
   /* Some Code */
   return 0;
}
int main()
{
   MyFunctionInArray = 
      AnyFunction; // Displays: "error: lvalue required as left operand of assignment"
}

GCC displays "error: lvalue required as left operand of assignment". How can I fix this? For my purpose, I could not call directly AnyFunction().


Solution

  • This will expand to:

       (type)xxx = ...
    

    This is not legal. However, you could use something like:

       * (type *)& xxx = ...