C99 allows arguments in the macro call to be empty and such a call should contain the same number of commas as in the pre-processor directive
At this time, the empty arguments will be replaced by an invisible placemarker tokens
#include <stdio.h>
#include <stdlib.h>
#define sum(a,b,c,d)(a+b+c+d)
int main()
{
int A=1;
int B=2;
int C=2;
int D=2;
int E=sum(A,B,C,D);
int F=sum(,B,C,D);
int G=sum(,,C,D);
int H=sum(,,,D);
printf("E=%d\n",E);
printf("F=%d\n",F);
printf("G=%d\n",G);
printf("H=%d\n",H);
return 0;
}
Output
E=7
F=6
G=4
H=2
Leave a Reply