On 2025-12-13 16:34, Alejandro Colomar wrote:
   #define ARRAY_OF_AT_LEAST(a,n) a[static n]
Please don't use [static n] ever.  I want to remove it from the
standard, and I think I'm quite advanced in convincing the right people.
If you start using it, that could be negative to my efforts.

I put a similar macro into Gnulib more than a decade ago with Gnulib's vla module, which does this:

  #ifdef __STDC_NO_VLA__
  # define VLA_ELEMS(n)
  #else
  # define VLA_ELEMS(n) static n
  #endif

... the idea being that you can use the syntax 'int foo[VLA_ELEMS (10)]' if you like. However, the only use I know of is the obsolescent program Gnu RCS that the module was introduced for. The late Thien-Thi Nguyen asked for VLA_ELEMS and used it mostly for documentation I think. See the thread starting at <https://lists.gnu.org/r/bug-gnulib/2014-08/msg00012.html>.

As I understand things, the main use of [static n] advocated by Jens Gustedt is as as a not-immediately-obvious way to assert that a pointer parameter is non-null. But for Gnulib-using software we use _GL_ATTRIBUTE_NONNULL for that instead. Although there's also a secondary use of [static n] to allow separately-compiled code to fetch contents of arrays more aggressively, I'm not sure the small benefit of that is worth the hassle.

I'd ask you to please avoid arrays of exactly n in general.

These are rare enough in GNU code (with its no-arbitrary-limits philosophy) that it's not clear it's worth the hassle of a Gnulib macro.

Reply via email to