Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1592785
| From | Måns Rullgård <mans@mansr.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: Arrays of variable length |
| Date | 2017-03-05 16:50 +0100 |
| Message-ID | <thGA1-2jU-3@gated-at.bofh.it> (permalink) |
| References | <thAXE-6JA-19@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Tomas Winkler <tomasw@gmail.com> 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 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. 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. -- Måns Rullgård
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Arrays of variable length Tomas Winkler <tomasw@gmail.com> - 2017-03-05 10:50 +0100
Re: Arrays of variable length Al Viro <viro@ZenIV.linux.org.uk> - 2017-03-05 11:10 +0100
Re: Arrays of variable length Måns Rullgård <mans@mansr.com> - 2017-03-05 16:50 +0100
Re: Arrays of variable length Henrique de Moraes Holschuh <hmh@hmh.eng.br> - 2017-03-05 22:20 +0100
Re: Arrays of variable length Richard Weinberger <richard.weinberger@gmail.com> - 2017-03-05 23:00 +0100
Re: Arrays of variable length Måns Rullgård <mans@mansr.com> - 2017-03-06 01:40 +0100
Re: Arrays of variable length Tomas Winkler <tomasw@gmail.com> - 2017-03-09 09:10 +0100
Re: Arrays of variable length Måns Rullgård <mans@mansr.com> - 2017-03-09 14:10 +0100
Re: Arrays of variable length Tomas Winkler <tomasw@gmail.com> - 2017-03-09 15:00 +0100
Re: Arrays of variable length Måns Rullgård <mans@mansr.com> - 2017-03-09 15:20 +0100
Re: Arrays of variable length Tomas Winkler <tomasw@gmail.com> - 2017-03-09 15:30 +0100
Re: Arrays of variable length Måns Rullgård <mans@mansr.com> - 2017-03-09 15:50 +0100
Re: Arrays of variable length Tomas Winkler <tomasw@gmail.com> - 2017-03-09 15:30 +0100
Re: Arrays of variable length Måns Rullgård <mans@mansr.com> - 2017-03-09 15:50 +0100
csiph-web