From: der.herr@hofr.at (Nicholas Mc Guire)
To: kernelnewbies@lists.kernelnewbies.org
Subject: &array[0] vs array
Date: Thu, 30 Mar 2017 16:05:51 +0000 [thread overview]
Message-ID: <20170330160551.GA32725@osadl.at> (raw)
In-Reply-To: <eed8bdcf-bb74-cb0d-aa85-3f705201c70d@mrbrklyn.com>
On Thu, Mar 30, 2017 at 09:04:35AM -0400, Ruben Safir wrote:
> On 03/29/2017 08:30 PM, Tobin C. Harding wrote:
> > Does the kernel community have a preference when using the address of
> > the first element of an an array?
> >
> > 1. addr = &array[0]
> > 2. addr = array;
> >
> > $ grep '\&.*\[0\]' | wc -l
> > 10077
> >
> > style (1) is clearly used, I was not able to grep for instances where
> > style (2) is used.
>
> maybe there is a another reason why 2 is not used.
>
the second form is used - just not quite as often
with the below quick (and probably incomplete) coccinelle script you
can find a few hundred occurences of the second form in linux-next
<snip>
virtual report
@v2@
identifier array,addr;
type T;
position p;
@@
(
* T array[];
|
* T array[] = ...;
)
...
* addr = array at p
@script:python@
p << v2.p;
@@
print "%s:%s" % (p[0].file,p[0].line)
<snip>
If its really obvious that its an array that you are manipulating
maybe the second version is fine - if its not so obvious the
first version makes it clear - and as readability is a key issue
for any complex code I suspect that readability explains the preference.
thx!
hofrat
next prev parent reply other threads:[~2017-03-30 16:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-30 0:30 &array[0] vs array Tobin C. Harding
2017-03-30 13:04 ` Ruben Safir
2017-03-30 16:05 ` Nicholas Mc Guire [this message]
2017-04-03 1:28 ` Tobin C. Harding
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=20170330160551.GA32725@osadl.at \
--to=der.herr@hofr.at \
--cc=kernelnewbies@lists.kernelnewbies.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.