How can I overcome the "error C2100: illegal indirection" when accessing the contents of a void* in VS2008

c, visual-studio-2008

Solution

Then how about:

void **ptr = (void **) &(*env)->GetVersion;
*ptr = <address of new function>

The right way to do this is to work with the type system, avoid all the casting and declare actual pointers to functions like:

typedef int (*fncPtr)(void);
fncPtr *ptr = &(*env)->GetVersion;
*ptr = NewFunction;

The above assumes GetVersion is of type fncPtr and NewFunction is declared as int NewFunction(void);

Problem

I have a C application that I've created in VS2008. I am creating a mock creation function that overrides function references in a struct. However if I try and do this in a straight forward fashion with something like: ``` void *ptr = &(*env)->GetVersion; *ptr = <address of new function> ``` then I get a "error C2100: illegal indirection" error as *ptr, when ptr is a void * seems to be a banned construct. I can get around it by using a int/long pointer as well, mapping that to the same address and modifying the contents of the long pointer: ``` *structOffsetPointer = &(*env)->GetVersion; functionPointer = thisGetVersion; structOffsetPointerAsLong = (long *)structOffsetPointer; *structOffsetPointerAsLong = (long)functionPointer; ``` but I am concerned that using long or int pointers will cause problems if I switch between 32 and 64 bit environments. So is there are easy way to disable this error? Assuming not, is either int or long 64 bits under win64?

Original source