Date: Mon, 15 Nov 2021 20:57:21 +0100
Damn, it even compiles without extern "C"
https://godbolt.org/z/8aaqjzMfa
On Mon, 15 Nov 2021 at 20:52, DBJ <dbj_at_[hidden]> 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_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?
>>
>> Kind regards ...
>>
>>
>>
>>>
>>>
https://godbolt.org/z/8aaqjzMfa
On Mon, 15 Nov 2021 at 20:52, DBJ <dbj_at_[hidden]> 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_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?
>>
>> Kind regards ...
>>
>>
>>
>>>
>>>
Received on 2021-11-15 13:57:46