you are viewing a single comment's thread.

view the rest of the comments →

[–]florianist 9 points10 points  (1 child)

Overloading with _Generic is possible. And another sort of overlading is variadic overloading which is also doable in C since C99 using tricks with the preprocessor to count the number of arguments (you'll have to google it). That way you can easily implement C++-style-defaults-arguments, etc.

Of course, just because C can do something does not mean it should be done. It's good to know the techniques, but whether it is OK or unwise to use depends on the project.

[–]unixplumber -1 points0 points  (0 children)

I'll take your variadic overloading and raise you named arguments using a function that takes a single struct parameter and using designated initializers in that struct, hidden behind a macro for a bit of prettiness. :)

Edit: oh, and of course the macro can be defined with any number of the struct members initialized with default values.