[lkml]   [2017]   [Mar]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: Arrays of variable length
Henrique de Moraes Holschuh <> writes:

> On Sun, 05 Mar 2017, Måns Rullgård wrote:
>> Tomas Winkler <> writes:
>> > 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
>> > 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.
>> Variable-length arrays are a very bad idea. Don't use them, ever.
>> If the size has a sane upper bound, just use that value statically.
>> Otherwise, you have a stack overflow waiting to happen and should be
>> using some kind of dynamic allocation instead.
>> Furthermore, use of VLAs generally results in less efficient code. For
>> instance, it forces gcc to waste a register for the frame pointer, and
>> it often prevents inlining.
> Well, if we're going to forbid VLAs in the kernel, IMHO the kernel build
> system should call gcc with -Werror=vla to get that point across early,
> and flush out any offenders.

If it were up to me, that's exactly what I'd do.

Måns Rullgård

 \ /
  Last update: 2017-03-06 01:32    [W:0.075 / U:2.236 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site