I have a question about functions and pointers to functions....
Why does a C program treat a function call to a function and a function call to a function pointer the same?
#include <stdio.h>
#include <stdlib.h>
typedef void (*funcptr)(void);
void myfunc(void)
{
fputs("Hello, World!\n", stdout);
}
int main(int argc, char**argv)
{
funcptr MyFunc = &myfunc;
myfunc();
MyFunc();
exit(EXIT_SUCCESS);
}
Program output:
Hello, World!
Hello, World!
When I compile the above program both the call to myfunc() and MyFunc() will produced the same result..."Hello, World" will be displayed. Now when I examine the asm instructions for this program, I find that the compiler was nice enough to dereference the function pointer for me.....Why does the language allow for this? Is there a reason to treat two different entities the same in source code but differently in the resulting asm code?....I hope this makes sense...I await your replies....Gerard4143