lkml.org 
[lkml]   [2017]   [Mar]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Arrays of variable length
On Sun, Mar 05, 2017 at 11:44:33AM +0200, Tomas Winkler wrote:
> Sparse complains for arrays declared with variable length
>
> 'warning: Variable length array is used'
>
> Prior to c99 this was not allowed but lgcc (c99) doesn't have problem
> with that https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html.
> And also Linux kernel compilation with W=1 doesn't complain.
>
> Since sparse is used extensively would like to ask what is the correct
> usage of arrays of variable length
> within Linux Kernel.

That depends. For structure members the answer is simply "don't, it's
not a valid C to start with". Note that this is about actual VLA, not
struct foo {
int bar;
struct baz[];
}
- that is valid C99 and sparse is just fine with it. For local variables...
keep in mind that kernel stack is _small_, so any VLA there needs to be
done very carefully. For heap it's more or less usable, but keep in mind
that gcc support of VLA (and variably-modified types in general) has
seriously unpleasant corner cases, especially when combined with the ({...})
thing. IOW, "doesn't have problem" is overoptimistic; use with care.

\
 
 \ /
  Last update: 2017-03-05 11:02    [W:0.069 / U:0.240 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site