On Wed, 3 Sep 2014, Florian Weimer wrote:
> > If you declare the size as [static sz] then
> > that means it points to an array of at least that size, but it could be
> > larger.
>
> GCC does not seem to enforce that. This compiles without errors:
[static] is about optimization (but GCC doesn't optimize using it either).
It's only undefined behavior if a call with a too-small array is actually
executed.
> int foo(char [static 5]);
>
> int
> bar(char *p)
> {
> return foo(p);
> }
That's perfectly valid, as long as every call to bar is with an argument
that does in fact point to at least 5 chars (if a call doesn't, there's
undefined behavior when that call is executed).
--
Joseph S. Myers
[email protected]