Hi Bruno,

On Tue, Jun 03, 2025 at 12:21:53AM +0200, Alejandro Colomar wrote:
> > 2025-06-02  Bruno Haible  <br...@clisp.org>
> > 
> >     stdcountof-h: Add tests.
> >     * tests/test-stdcountof-h.c: New file.
> >     * tests/test-stdcountof-h-c++.cc: New file.
> >     * modules/stdcountof-h-tests: New file.
> >     * modules/stdcountof-h-c++-tests: New file.
> > 
> >     stdcountof-h: New module.
> >     * lib/stdcountof.in.h: New file.
> >     * m4/stdcountof_h.m4: New file.
> >     * modules/stdcountof-h: New file.
> 
> Minor issue:
> 
>       An <stdcountof.h> that is like C23.
> 
> That should say C2y; C23 didn't have <stdcountof.h>.

Oh, and another issue:

        $ grepc countof .
        ./lib/stdcountof.in.h:#define countof(a) \
          (sizeof (a) / sizeof (a[0]) + 0 * _gl_verify_is_array (a))

(a[0]) should be ((a)[0])
Otherwise, a weird argument could misbehave.  I think it's not easy to
pass something bad, but I don't know; people invent weird stuff all the
time.

I suggest applying this:

        diff --git i/lib/stdcountof.in.h w/lib/stdcountof.in.h
        index 3bbb78390a..af62b4d45b 100644
        --- i/lib/stdcountof.in.h
        +++ w/lib/stdcountof.in.h
        @@ -33,7 +33,7 @@
              void func (int a[10]) { ... }
          */
         #define countof(a) \
        -  (sizeof (a) / sizeof (a[0]) + 0 * _gl_verify_is_array (a))
        +  (sizeof (a) / sizeof ((a)[0]) + 0 * _gl_verify_is_array (a))
         
         /* Attempts to verify that A is an array.  */
         #if defined __cplusplus



Have a lovely night!
Alex

> 
> BTW, do you have in plans for using this module within gnulib itself?
> 
> 
> Have a lovely night!
> Alex
> 
> -- 
> <https://www.alejandro-colomar.es/>



-- 
<https://www.alejandro-colomar.es/>

Attachment: signature.asc
Description: PGP signature

Reply via email to