This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Couldn't `function(arg[static 3])` imply nonnull and array size in C?
- From: Campbell Barton <ideasman42 at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sun, 3 May 2015 03:35:47 +1000
- Subject: Couldn't `function(arg[static 3])` imply nonnull and array size in C?
- Authentication-results: sourceware.org; auth=none
Hi, using GCC 5.1 found that using static can be used to define a
variable as having at least N elements in the array, and that its not
NULL.
See: http://www-01.ibm.com/support/knowledgecenter/SSLTBW_1.12.0/com.ibm.zos.r12.cbclx01/param_decl.htm%23param_decl__static_array_index
Given the simple function:
void print_v3(float v[static 3])
{
printf("%f %f %f\n", v[0], v[1], v[2]);
}
Calling `foo(NULL);` or `{ float v[2]; foo(v); }` should be able to
cause a warning, it would be useful since this is a farily
In fact I found Clang 3.6 does this already. eg:
warning: array argument is too small; contains 2 elements, callee
requires at least 3 [-Warray-bounds]
Is there any reason GCC couldn't do the same?
--
- Campbell