D
dis
The following code introduces a 'generic function pointer' p. When calling
the pointed-to function via this p, one has to typecast p towards a pointer
to the type of the pointed-to function. My question is how to do this if the
pointed-to function is a K&R style declared function, like f. The best I
could come up with is a typecast towards a pointer to a function with
unspecified number and type of parameters (and appropriate return type), as
illustrated in the code below. Is this approach compliant with the C
standard?
f(a) float a;
{
return a;
}
main()
{
void (*p)() = (void(*)())f;
((int(*)())p)(2.3f);
return 0;
}
the pointed-to function via this p, one has to typecast p towards a pointer
to the type of the pointed-to function. My question is how to do this if the
pointed-to function is a K&R style declared function, like f. The best I
could come up with is a typecast towards a pointer to a function with
unspecified number and type of parameters (and appropriate return type), as
illustrated in the code below. Is this approach compliant with the C
standard?
f(a) float a;
{
return a;
}
main()
{
void (*p)() = (void(*)())f;
((int(*)())p)(2.3f);
return 0;
}