Damn, it even compiles without extern "C"


On Mon, 15 Nov 2021 at 20:52, DBJ <dbj@dbj.org> wrote:
Also, this compiles in clang 13: (https://godbolt.org/z/KPexW755Y)

template<typename T, size_t N>
auto consume_array ( const T (&arr)[N])
{
   return N ;
}

extern "C" {
unsigned consume_array_the_c_way ( const unsigned N, const char arr[static N])
{
   return N ;
}
}

int main()
{
     int intarr[] = {0,1,2,3};
     assert( consume_array( intarr ) == 4 ) ;

     char charr[4] = {0};
     assert( consume_array_the_c_way( sizeof(charr), charr) == 4);

    return 42;
}

Which, one might assume, is not totally standard C++?


On Mon, 15 Nov 2021 at 20:28, DBJ <dbj@dbj.org> 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?

Kind regards ...