Date: Tue, 12 Aug 2025 09:39:59 +0200
Am Dienstag, dem 12.08.2025 um 09:23 +0200 schrieb Jens Maurer:
> On 12.08.25 08:46, Martin Uecker wrote:
> > It certainly does in C:
> > https://godbolt.org/z/bGPM8K4br
>
> Quoting the example here for easier reference:
>
> int foo(int n, char buf[n]);
>
> int main()
> {
> char buf[100];
> foo(101, buf);
> }
>
>
> gcc with -Wall gives a warning (not an error) and clang is silent.
Different compilers warn about different things. It is
useful in practice.
>
> That makes me wonder about the state of standardization
> of this situation: Could you point me to the C rule that
> specifies how the above should be handled? Given that 101
> is a constant, does C make the above ill-formed?
In this case, "n" is simply ignored. But already in the
past WG14 encouraged the use of this notation for static analysis and
warnings, and there is some interest in strengthening the
semantics.
Martin
> On 12.08.25 08:46, Martin Uecker wrote:
> > It certainly does in C:
> > https://godbolt.org/z/bGPM8K4br
>
> Quoting the example here for easier reference:
>
> int foo(int n, char buf[n]);
>
> int main()
> {
> char buf[100];
> foo(101, buf);
> }
>
>
> gcc with -Wall gives a warning (not an error) and clang is silent.
Different compilers warn about different things. It is
useful in practice.
>
> That makes me wonder about the state of standardization
> of this situation: Could you point me to the C rule that
> specifies how the above should be handled? Given that 101
> is a constant, does C make the above ill-formed?
In this case, "n" is simply ignored. But already in the
past WG14 encouraged the use of this notation for static analysis and
warnings, and there is some interest in strengthening the
semantics.
Martin
Received on 2025-08-12 07:40:04