#include<stdio.h>
void f(int a)
{
printf("%d", a);
}
#define f(a) {}
int main()
{
/* call f : function */
}
How to call f
(the function)? Writing f(3)
doesn't work because it is replaced by {}
#include<stdio.h>
void f(int a)
{
printf("%d", a);
}
#define f(a) {}
int main()
{
/* call f : function */
}
How to call f
(the function)? Writing f(3)
doesn't work because it is replaced by {}
Does (f)(3);
work?
The C preprocessor doesn't expand the macro f
inside ( )
.
int main()
{
#undef f // clear f!
f(3);
}
Use function pointer to achieve this:
int main() {
void (*p)(int a);
p = f;
p(3); //--> will call f(3)
return 0;
}
One solution is posted by @Prasoon, another could be just introducing another name for the function, IF you can't change the function's name, neither the macro's name:
#include<stdio.h>
void f(int a)
{
printf("%d", a);
}
#define fun (f) //braces is necessary
#define f(a) {}
int main()
{
fun(100);
}
Online demo : http://www.ideone.com/fbTcE