Paul Eggert wrote in
<https://lists.gnu.org/archive/html/autoconf/2025-10/msg00007.html>:
> "VLA_STATIC" is still too long. Also, the name is confusing,
> because it's a macro for declaring pointer objects that have automatic
> (not static) storage duration. (This is a beef I have with the keyword
> "static" in the first place, of course.)

I agree with that. Use of the same keyword to mean totally different things
is not making code easier to read. The WG14 committee needs a reality check...

> in the GNU world people 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, 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",
> without also saying, "hey, GCC has something better".

This __attribute__ syntax is more powerful for the special case of
two (or more) arguments that have a constraint together. But the vast
majority of per-argument annotations refer to a single argument, and
I find this syntax

extern nullable variant_key_t
       create_variant_key (nonnull literal_t literal);
extern nullable variant_key_t
       create_variant_key_otherwise (nullable string_t identifier);
extern nullable message_t
       u8_parse_message (const uint8_t *nonnull message, errors_t *nonnull 
errors);

much more readable than

extern variant_key_t
       create_variant_key (nonnull literal_t literal)
       __attribute__ ((__nonnull__ (1)));
extern variant_key_t
       create_variant_key_otherwise (string_t identifier);
extern message_t
       u8_parse_message (const uint8_t *message, errors_t *errors);
       __attribute__ ((__nonnull__ (1, 2)));

These two identifiers 'nonnull', 'nullable' are supported by clang, like this:
#if __clang_major__ >= 4
# define nullable _Nullable
# define nonnull _Nonnull
#else
# define nullable
# define nonnull
#endif

Therefore, I wouldn't say that the GCC __attribute__ attribute syntax is
"better".

Bruno




  • Detect if t... Antonin Décimo
    • Re: De... Jacob Bachmeyer
    • Re: De... Antonin Décimo
      • Re... Paul Eggert
        • ... Antonin Décimo
          • ... Paul Eggert
            • ... Antonin Décimo
              • ... Antonin Décimo
                • ... Paul Eggert
    • Re: De... Bruno Haible via Discussion list for the autoconf build system

Reply via email to