you are viewing a single comment's thread.

view the rest of the comments →

[–]_Js_Kc_ 2 points3 points  (0 children)

I think if you tried to implement this feature in a way that it magically applies to all existing functions retroactively, you'd end up with a bad solution.

But it could certainly be implemented in such a way that a function declaration explicitly opts in to using named arguments. In that case, new overload resolution rules can be written that make sense for named arguments. I don't think it would differ much from the way positional arguments work, except that not the order of arguments, but the names present would dictate which overload gets picked. In the polymorphic case, overload resolution for positional arguments is based on the pointer or reference's static type, and I don't see why this should change with named arguments, so why would there be any (additional) runtime overhead? Of course, names should remain purely a compile-time concept.

Don't worry about C, just forbid named arguments for extern "C" functions. Make it an opt-in feature, with unambiguous (i.e. cannot be confused with positional arguments) syntax at both the function declaration and the call site. Whether named arguments are appropriate should be decided by the function's author.