J
John Turner
typedef void (*vfp)();
typedef vfp (*fp)();
static fp hello()
{
printf("Hello.\n");
return (fp)&hello;
}
main(){
hello()()();
}
Here we have a function that returns a fp, which is a function pointer
typedef, the function of which returns a vfp, which is another function
pointer typedef but which returns void, so we can use hello()()(); but
not hello()()()(); unless we have a cast. I was wondering if there's a
way to do this properly with some kind of properly recursive typedef. I
saw an example of how to do this fairly "nicely" in C++ but couldn't
find anything for C itself. Anyone here know how to do this? Purely
theoretical by the way, wouldn't want to release this on some poor,
unsuspecting, real project.
Cheers,
John
typedef vfp (*fp)();
static fp hello()
{
printf("Hello.\n");
return (fp)&hello;
}
main(){
hello()()();
}
Here we have a function that returns a fp, which is a function pointer
typedef, the function of which returns a vfp, which is another function
pointer typedef but which returns void, so we can use hello()()(); but
not hello()()()(); unless we have a cast. I was wondering if there's a
way to do this properly with some kind of properly recursive typedef. I
saw an example of how to do this fairly "nicely" in C++ but couldn't
find anything for C itself. Anyone here know how to do this? Purely
theoretical by the way, wouldn't want to release this on some poor,
unsuspecting, real project.
Cheers,
John