For functions with many parameters, such as UI library functions, it is difficult to remember the parameter types and meanings at each location, especially in the development environment where your ide is relatively simple, you may need to query documents frequently.
For languages like python, native supports named parameters, such
Def func (name, age): Print name, agefunc ('aaa', 1) func (age = 2, name = 'bbb ')
Maybe your function has 10 parameters, most of which can have default values. Therefore, if you need to specify the values of 3rd and 5th parameters, when other parameters use the default behavior, It is very convenient to call "func (arg3 = 3, arg5 = 5.
To implement the features of named parameters in c89 (My compiler is still GCC 4.7.2), you can use the techniques mentioned in this article.
The following is the macro I wrote:
# Include <stdio. h> # define function (Ret, funcname ,...) struct _ ARGs _ # funcname {__ va_args __}; RET funcname (struct _ ARGs _ # funcname ARGs) # define call (funcname ,...) func (struct _ ARGs _ # funcname) {__ va_args __}) function (void, func, const char * Name; int age;) {printf ("Name: % s \ n age: % d \ n ", argS. name, argS. age);} int main () {call (func, "aa123", 10); Call (func ,. age = 5 ,. name = "abc456"); Call (func ,. name = "def789"); Call (func ,. age = 11 );}
Moreover, compared with common functions, functions defined in this way are basically non-destructive in performance.