Hi Daniel,

On 2026-01-28T10:14:23+0000, Daniel Thompson wrote:
> On Mon, Jan 26, 2026 at 01:49:16PM +0100, Alejandro Colomar wrote:
> > Proposed wording
> >     Based on N3685.
> >
> >     6.7.7.3  Array declarators
> >     @@ Constraints, p1
> >      In addition to optional type qualifiers and the keyword static,
> >      the [ and ] can delimit an expression or *.
> >      If they delimit an expression,
> >      called the array length expression,
> >      the expression shall have an integer type.
> >      If the expression is a constant expression,
> >     -it shall have a value greater than zero.
> >     +it shall have a nonnegative value.
> >     +An array length expression
> >     +that is a constant expression with value zero
> >     +shall appear only in
> >     +a declaration of a function parameter with an array type,
> >     +and then only in the outermost array type derivation.
> 
> This change did not have any motivating example within the discussion.
> Providing a motivational example showing why it is useful to allow array
> parameters whose constant length is zero would be good.

Makes sense; I'll add that.

Here's a function that I use in shadow-utils:

        char *
        stpecpy(char dst[], const char end[];
            char dst[dst?end-dst:0], const char end[0], const char *restrict 
src)
        {
                ssize_t  dlen;

                if (dst == NULL)
                        return NULL;

                dlen = strtcpy(dst, src, end - dst);
                if (dlen == -1)
                        return NULL;

                return dst + dlen;
        }

It's essentially the same as Plan9's strecpy(2), except that Plan9's
API has an important bug.

Here's a GCC bug that shows such a use case:
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108036>


Have a lovely day!
Alex

> Daniel.

-- 
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature

Reply via email to