Cool Shell
The following section of the program is a small C language skill. It shows how to convert a function with a struct parameter into a Variable Parameter Function, the macro and built-in macro "_ VA_ARGS _" are used. The following program can be compiled normally under GCC:
1234567891011121314151617181920 # include <stdio. h> # define func (...) myfunc (struct mystru) {__ VA_ARGS __}) struct mystru {const char * name; int number ;}; void myfunc (struct mystru MS) {printf ("% s: % d ", ms. name? : "Untitled", ms. number);} int main (int argc, char ** argv) {func ("three", 3); func ("hello"); func (. name = "zero"); func (. number = argc ,. name = "argc",); func (. number = 42); return 0 ;}
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:
12345 myfunc (struct mystru) {"three", 3}); myfunc (struct mystru) {"hello"}); myfunc (struct mystru ){. name = "zero"}); myfunc (struct mystru ){. number = argc ,. name = "argc",}); myfunc (struct mystru ){. number = 42 });