[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] regex: use C99-style array arg syntax

From: Paul Eggert
Subject: Re: [PATCH] regex: use C99-style array arg syntax
Date: Fri, 27 Aug 2021 11:57:15 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

On 8/27/21 2:56 AM, Bruno Haible wrote:

So, to make the __access__ attribute [1] really consistent, they would need to
add a fifth access-mode 'any', that would not restrict the access pattern.

Yes, something like that might make sense. I would suggest something more general, though, along the lines of "might write" vs "shall write", which is the underlying issue here.

    void g (int n, int a[n]) { }
    void h (int n, int a[static n]) { }

So, the 'g' syntax is a somewhat broken language feature, since the compiler
can use it for warnings but not for optimizations.


And the essential difference between 'g' and 'h' is that g accepts a NULL
argument, whereas 'h' doesn't.

Another important difference is that in 'g', even when 'a' is nonnull there is no requirement that the first 'n' elements of 'a' must be accessible. In 'h' it's required.

How about this comment for _REGEX_NELTS, then?

/* Specify the number of elements of a function's array parameter,
    as in 'int f (int n, int arr[_REGEX_NELTS (n)]);'
    if arr may be NULL,
    or    'int f (int n, int arr[_REGEX_NELTS (static n)]);'
    if arr must be non-NULL.  */

After my earlier misadventures here I'm reluctant to document the "static" stuff (which isn't used or likely to be used in regex). And I hope that this is a one-off macro that we don't encourage elsewhere or even document, given that it's a public glibc header and that __attribute__ ((alloc ...)) is usually a better way to go.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]