{
printf("\nold style pf = %p\n", pf);
if (pf != NULL)
{
int x = (*pf)(12); // Using * to deref function pointer.
printf("pf(12) = %d\n", x);
}
}
{
printf("\nnew style pf = %p\n", pf);
if (pf != NULL)
{
int x = pf(12); // Don't need * to deref function pointer, either.
printf("pf(12) = %d\n", x);
}
}
{
printf("\nblock pf = %p\n", pf);
if (pf != NULL)
{
int x = pf(12); // Same syntax as calling function or function-pointer.
printf("pf(12) = %d\n", x);
}
}
/*
void functionTakingFunctionPointer(funcPtr fp);
This is how I create a typedef for a function pointer type:
*/
{
return i + 1;
}
{
// "old" style C code - using "&" take address of the function.
functionTakingFunctionPointerOldStyle( NULL );
functionTakingFunctionPointerOldStyle( & FuncionTakingIntReturningInt );
functionTakingFunctionPointerNewStyle( NULL );
functionTakingFunctionPointerNewStyle( FuncionTakingIntReturningInt );
functionTakingBlock( NULL );
functionTakingBlock( ^(int i){ return i + 1; } );
}
pf(12) = 13
pf(12) = 13
pf(12) = 13