On 2025-12-14 13:18, Alejandro Colomar wrote:

In GNU C, [n] means you can
access the first n elements.

Oh, I didn't know that. Where is this documented? I looked in the GCC manual but couldn't find it.

Also, how can one tell that GNU C supports this extension? Is there a sample program illustrating the support? Which versions of GCC support the extension?


At least, I'd suggest that gnulib uses [n] in GCC, and leaves [static n]
for those crappy dialects where [n] means nothing.

Well, as present Gnulib code is not using this GCC extension and as far as I can see it is unlikely to use the extension, at least not until many years after it's standardized, as it's too much of a pain to use the extension in code meant to be portable to non-GNU compilers.


The problem is that static checking of null pointers is incomplete, or
so I remember.  It's been a long time since I last checked that.

Of course one cannot do a "perfect" job of static checking - that's equivalent to solving the halting problem. But that's OK, the static checking suffices for practical code. Plus, the dynamic checking in functions like execl is needed only for broken callers - as far as I know it's present only for compatibility with mistakes made back in the 1970s (back when null pointers could be dereferenced! the good old days...).


You still get static checking with [[gnu::nonnull()]] and
-fno-delete-null-pointer-checks.  I don't use
-fno-delete-null-pointer-checks to remove dynamic checks, but to not
allow the compiler to abuse UB in the few cases where the compiler is
unable to diagnose.

Those two things are the same thing, right? I'm not quite following.

But anyway, this is low priority as we need not cater to unportable apps that pass null pointers to the likes of execl.

Reply via email to