Can one resolve the call to ensure that the function gets called?
Here is an example of how to do so
#include < stdlib.h >
int
max(int a, int b)
{
printf("calling function max\n");
return ((a > b) ? a : b);
}
#define max(a, b) ((a > b) ? (a) : (b))
int
main(void)
{
int i = 10, j = 5;
printf("1) %d\n", max(i, j));
i = 5;
j = 10;
printf("2) %d\n", (*max)(i, j));
return 0;
}
The good thing about C programming is that the function name also acts a function pointer. In addition, a function can be called by its name or called by dereferencing the function pointer.
No comments:
Post a Comment