C++ Logo

std-proposals

Advanced search

Re: Arrays (VLAs) as function parameters (as in C99)

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Mon, 15 Nov 2021 14:54:23 -0500
On Mon, Nov 15, 2021 at 2:29 PM DBJ via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Please excuse my ignorance. If we have this in the core language:
>
> template<typename T, size_t N>
> auto consume_array ( const T (&arr)[N])
> {
> return N ;
> }
>
> Why would we need:
>
> auto consume_array_as_modern_c_does ( const int N, const char arr[ static N] )
> {
> return N ;
> }
>
> I might be missing here something obvious?

Because the whole point is C compatibility, and that's not compatible with C.

Also, you can't call that with a bare pointer (not without explicitly
specifying template parameters).

Received on 2021-11-15 13:54:37