kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: me@tobin.cc (Tobin C. Harding)
To: kernelnewbies@lists.kernelnewbies.org
Subject: &array[0] vs array
Date: Mon, 3 Apr 2017 11:28:59 +1000	[thread overview]
Message-ID: <20170403012859.GJ3755@eros> (raw)
In-Reply-To: <20170330160551.GA32725@osadl.at>

On Thu, Mar 30, 2017 at 04:05:51PM +0000, Nicholas Mc Guire wrote:
> 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.

Got it, readability over brevity.

thanks,
Tobin.

      reply	other threads:[~2017-04-03  1:28 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
2017-04-03  1:28     ` Tobin C. Harding [this message]

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=20170403012859.GJ3755@eros \
    --to=me@tobin.cc \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).