Empty macro arguments with C99

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

Mohammed Anees

Hey there, welcome to aneescraftsmanship I am Mohammed Anees an independent developer/blogger. I like to share and discuss the craft with others plus the things which I have learned because I believe that through discussion and sharing a new world opens up

Leave a Reply

Your email address will not be published.