From: Al Viro <viro@ZenIV.linux.org.uk>
To: Tomas Winkler <tomasw@gmail.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
sparse@vger.kernel.org
Subject: Re: Arrays of variable length
Date: Sun, 5 Mar 2017 10:01:35 +0000 [thread overview]
Message-ID: <20170305100116.GH29622@ZenIV.linux.org.uk> (raw)
In-Reply-To: <CA+i0qc5_NFqb=_6P46yrebrQYzSuCCKgq_xyeui_x6nTRGx62A@mail.gmail.com>
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.
next prev parent reply other threads:[~2017-03-05 10:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-05 9:44 Arrays of variable length Tomas Winkler
2017-03-05 10:01 ` Al Viro [this message]
2017-03-05 14:27 ` Måns Rullgård
2017-03-05 21:12 ` Henrique de Moraes Holschuh
2017-03-05 21:49 ` Richard Weinberger
2017-03-06 0:31 ` Måns Rullgård
2017-03-09 7:54 ` Tomas Winkler
2017-03-09 13:02 ` Måns Rullgård
2017-03-09 13:40 ` Tomas Winkler
2017-03-09 14:16 ` Måns Rullgård
2017-03-09 14:21 ` Tomas Winkler
2017-03-09 14:26 ` Måns Rullgård
2017-03-09 14:29 ` Tomas Winkler
2017-03-09 14:38 ` Måns Rullgård
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170305100116.GH29622@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=sparse@vger.kernel.org \
--cc=tomasw@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox