Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1175603
| From | Joe Perches <joe@perches.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: RFC: kernel coding style: prefer array to &array[0] ? |
| Date | 2015-07-02 01:10 +0200 |
| Message-ID | <pHziG-3cE-23@gated-at.bofh.it> (permalink) |
| References | (1 earlier) <pHoQj-4Hd-23@gated-at.bofh.it> <pHp9E-53k-5@gated-at.bofh.it> <pHpjk-56P-19@gated-at.bofh.it> <pHrEt-6sY-9@gated-at.bofh.it> <pHyPE-2MU-13@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Wed, 2015-07-01 at 15:33 -0700, Dmitry Torokhov wrote: > On Wed, Jul 01, 2015 at 07:53:44AM -0700, Joe Perches wrote: > > On Wed, 2015-07-01 at 14:26 +0200, Julia Lawall wrote: > > > On Wed, 1 Jul 2015, Dan Carpenter wrote: > > > > On Wed, Jul 01, 2015 at 01:54:29PM +0200, Clemens Ladisch wrote: > > > > > Joe Perches wrote: > > > > > > It seems most in-kernel uses are 'array' rather than '&array[0]' > > > > > > > > > > > > Most of the time, using array is simpler to read than &array[0]. > > > > > > > > > > > > Exceptions exists when addresses for consecutive members are > > > > > > used like func(&array[0], &array[1]); > > > > > > > > > > I use '&array[0]' when I want to get a pointer to a single object that > > > > > happens to be the first one in an array. > > > > > > > > Yeah. Of course, you're right. Otherwise it ends up confusing static > > > > checkers if you want the first element or the whole array. > > > > Right. > > > > > > > > Should this preference be put into checkpatch and/or CodingStyle? > > > > And checkpatch will have no idea what the prototype > > for any function is, so this transform is better left > > for smarter tools like coccinelle. > > > > The proper answer here is no. [] > CHECK: Using addressof array 'mtouch->data' index [0] may be simpler as > 'mtouch->data' > #97: FILE: drivers/input/touchscreen/mtouch.c:97: > + if (MTOUCH_FORMAT_TABLET_STATUS_BIT & mtouch->data[0]) The joys of perl parsing. > CHECK: Using addressof array 'msg' index [0] may be simpler as 'msg' > #38: FILE: drivers/input/touchscreen/ipaq-micro-ts.c:38: > + be16_to_cpup((__be16 *) &msg[0])); That's using the first member in an array. > I'd be OK with changing cases like: > > CHECK: Using addressof array 'buf' index [0] may be simpler as 'buf' > #232: FILE: drivers/input/touchscreen/zforce_ts.c:232: > + return zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf)); I think cases like those are sensible to change. cheers, Joe -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: RFC: kernel coding style: prefer array to &array[0] ? Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2015-07-02 00:40 +0200 Re: RFC: kernel coding style: prefer array to &array[0] ? Joe Perches <joe@perches.com> - 2015-07-02 01:10 +0200
csiph-web