C99 introduced the concept of designated initializers, that allows to
initialize a structure using the name of the fields, like this:
Here is a C macro that extends this syntax to function calls.
I present it as a curiosity, and I really wouldn’t advise anybody to actually
use it in a project (except maybe for very special cases, like for example
emulating the interface of a language that accepts named arguments).
[Edit] As some people pointed out on the hacker news thread, the macro
also uses a statement expression, which is a GNU C extension, and so it would
probably not work with MSVC (I am not going to try).
And here is how we can use it:
For the curious, here is what the macro expends to:
The macro can only support up to 5 arguments (but, could easily be extended for
more). One interesting thing is that if we omit a parameter it will be
automatically set to 0. So let say you have a function like:
And you want to call it by setting most of the arguments to 0. You could do: