-
Casting Problem
I am having a problem casting a void* into a function address:
void Attempt(void* fun){
void (*function)(void) = ????;
function();
}
I've tried:
void (*function)(void) = ((void)(*)(void))fun;
and even:
void (*function)(void) = ((void)(*fun)(void));
...among others....
-
Stupid me, it was:
void(*function)(void) = (void(*)(void))fun;
...it was the extra parenthesis around the first "void"...
-
Like this maybe?
Code:
#include <stdio.h>
void printInt(int value)
{
printf("%d\n", value);
}
void Attempt(void* fun)
{
void (*function) (int) = (void(*)(int))fun;
function(125);
}
int main()
{
Attempt((void*)&printInt);
return 0;
}
EDIT - Damn got beat. I've always hated function pointer syntax.