This is the mail archive of the
mailing list for the GCC project.
Re: Bounded array type?
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: James Nelson <retrobanana dot jn at gmail dot com>, <gcc at gcc dot gnu dot org>
- Date: Wed, 3 Sep 2014 16:23:21 +0000
- Subject: Re: Bounded array type?
- Authentication-results: sourceware.org; auth=none
- References: <CAGrc-OBDFPeTK1T0VRrO2TWKmSthhTywf6+78aR4L-_+ybu4uA at mail dot gmail dot com> <5406C8A4 dot 9060902 at redhat dot com> <Pine dot LNX dot 4 dot 64 dot 1409031517420 dot 11036 at digraph dot polyomino dot org dot uk> <54073D01 dot 6070403 at redhat dot com>
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
> int foo(char [static 5]);
> 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