The following section of the program is a small C language skill. It shows how to convert a function whose parameter is a struct into a Variable Parameter Function, in which macro and inner macro are used.__VA_ARGS__", The following program can be compiled normally under GCC:
# Include <stdio. h> </P> <p> # define func (...) myfunc (struct mystru) {__ va_args __}) </P> <p> struct mystru {const char * Name; int number ;}; </P> <p> void myfunc (struct mystru MS) <br/> {<br/> printf ("% s: % d/N", Ms. name? : "Untitled", Ms. number); <br/>}</P> <p> int main (INT argc, char ** argv) <br/>{< br/> func ("three", 3); <br/> func ("hello"); <br/> func (. name = "zero"); <br/> func (. number = argc ,. name = "argc",); <br/> func (. number = 42); </P> <p> return 0; <br/>}< br/>
From the above section of the program, we can see that a function called myfunc is changed by the macro of func. What myfunc needs is a structure called mystru. However, through the macro, the parameter struct mystru is changed to a function in the Variable Parameter List. The above program is output,
Three: 3
Hello: 0
Zero: 0
Argc: 1
Untitled: 42
Although this is not a good practice, you can learn about the strange usage of C in this world from another aspect. If you expand the macro, you will understand why. The following is the macro scale:
Myfunc (struct mystru) {"three", 3}); </P> <p> myfunc (struct mystru) {"hello "}); </P> <p> myfunc (struct mystru ){. name = "zero"}); </P> <p> myfunc (struct mystru ){. number = argc ,. name = "argc",}); </P> <p> myfunc (struct mystru ){. number = 42}); <br/>