Hi Alejandro,

> -  I have plans for improving _Countof as a GNU extension to work on
>    array parameters to functions.  I mean making this possible:
> 
>       wchar_t *
>       wmemset(size_t n; wchar_t wcs[n], wchar_t wc, size_t n)
>       {
>               for (size_t i = 0; i < countof(wcs); i++)
>                       wcs[i] = wc;
>               return wcs;
>       }

The sizeof operator does not work well in this case, right? So that would be
a case where countof works _better_ than sizeof.

>    What worries me of adding countof to C++ is that they may use it in
>    some way that could preclude my planned extension.  So I'll not
>    remind C++ people about this until I made sure my extension is
>    deployed in both GCC and Clang, and maybe in ISO C.

While I understand this, it still means that gnulib — which strives to make
the same code usable in C++ like in C — will probably have to override
<stdcountof.h> roughly like this:

  #ifdef __cplusplus
  template <typename T, size_t N>
  constexpr size_t countof(T const (&)[N]) {
    return N;
  }
  #else
  # define countof _Countof
  #endif

(And I have no idea whether this definition will work for variable-sized
arrays and for function parameters.)

Bruno




Reply via email to