Re: Detect if the static keyword is supported in array type derivations in function parameters
Paul Eggert <[email protected]> Tue, 7 Oct 2025 00:20:12 -0700
| Newsgroups | gmane.comp.sysutils.autoconf.general |
|---|---|
| Organization | UCLA Computer Science Department |
| Message-ID | <[email protected]> |
On 2025-10-06 16:50, Antonin D=C3=A9cimo wrote:
>> The macro name seems pretty long, given how commonly used this would
>> be for code that uses Gustedt's style. How about a shorter name like
>> "ATIC", short for "Array TINIEST INDEX COUNT"? This macro name is
>> short and (unlike "STATIC") is unlikely to be used in existing code.
>=20
> I'm not sure... Unfortunately this is unlike
> AC_C_{REGISTER,VOLATILE,INLINE} because it's only in this context that
> static isn't supported. Maybe VLA_STATIC? FWIW a lookup on GitHub did
> not return exact matches.
"VLA_STATIC" is still too long. Also, the name is confusing, because=20
it's a macro for declaring pointer objects that have automatic (not=20
static) storage duration. (This is a beef I have with the keyword=20
"static" in the first place, of course.) And these objects are not VLAs;=20
they merely have a VLA type.
Admittedly "ATIC", while short, is not a great name either. How about=20
"ATLEAST" instead? Although it's longer, it's more self-explanatory.=20
Code would look like this:
int strcmp (char const a[ATLEAST 1], char const b[ATLEAST 1]);
and this is more self-explanatory than "static" is.
> Note that the semantics changed between C17 (6.10.8.3):
Yes, I suppose ATLEAST can mean "static" for C11 and later, the empty=20
string earlier (roughly speaking, depending on what compilers actually=20
support).
In contrast, __STDC_NO_VLA__ is kinda tricky and I suppose should be a=20
separate issue.
An issue related to ATLEAST, though, is that in the GNU world people=20
typically use the nonnull attribute instead, e.g.:
int strcmp (char const *, char const *)
__attribute__ ((__nonnull__ (1,2)));
An advantage of this approach is that it's more flexible and powerful,=20
for example:
void *memcpy (void *, void const *, size_t)
__attribute__ ((__nonnull_if_nonzero__ (1, 3),
__nonnull_if_nonzero__ (2, 3)));
which is something that the "static" syntax cannot say.
So I'm not sure that Autoconf should be pushing only C23-style "static",=20
without also saying, "hey, GCC has something better".