C++ Logo

std-discussion

Advanced search

Re: Explicit and implicit parameter counts

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Fri, 3 Sep 2021 11:11:44 -0400
On Fri, Sep 3, 2021 at 10:49 AM Rick C. Hodgin via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> Greetings.
>
> Since we can define explicitly required parameters, and implicitly
> required parameters (populated with default values), I'd like to
> propose a way to know the number of each provided to a function by its
> caller.

No. This would break basically every ABI, since none of them currently
provide this information to a function. The ABI would therefore have
to create a new channel for said information, as well as compile
functions with default parameters differently from functions without
default parameters.

Most important of all... a function's *definition* doesn't have to
have default parameters. Indeed, declarations of the same functions in
different TUs can have *different* default parameters. And that's 100%
OK as far as C++ is concerned. Function pointers don't even carry
default parameters around.

And no, you can't put this into the function at compile-time.
Different functions called in different ways would basically be
different functions, since their contents would be different. That's
not a thing C++ can do.

At least, not outside of templates. So the only way this could
possibly work is if those are template functions with a hidden
template parameter which is the number of arguments passed to them.
And template definitions have to be visible to the caller.

And that's just not worth the effort. Not unless you can come up with
a use case that's *really* compelling.

Default parameters are not a real thing in C++. They're syntactic
sugar that only exists at the call site. That's just what the feature
is.

Received on 2021-09-03 10:11:57