* &array[0] vs array
@ 2017-03-30 0:30 Tobin C. Harding
2017-03-30 13:04 ` Ruben Safir
0 siblings, 1 reply; 4+ messages in thread
From: Tobin C. Harding @ 2017-03-30 0:30 UTC (permalink / raw)
To: kernelnewbies
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.
thanks,
Tobin.
^ permalink raw reply [flat|nested] 4+ messages in thread
* &array[0] vs array
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
0 siblings, 1 reply; 4+ messages in thread
From: Ruben Safir @ 2017-03-30 13:04 UTC (permalink / raw)
To: kernelnewbies
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.
--
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013
^ permalink raw reply [flat|nested] 4+ messages in thread
* &array[0] vs array
2017-03-30 13:04 ` Ruben Safir
@ 2017-03-30 16:05 ` Nicholas Mc Guire
2017-04-03 1:28 ` Tobin C. Harding
0 siblings, 1 reply; 4+ messages in thread
From: Nicholas Mc Guire @ 2017-03-30 16:05 UTC (permalink / raw)
To: kernelnewbies
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* &array[0] vs array
2017-03-30 16:05 ` Nicholas Mc Guire
@ 2017-04-03 1:28 ` Tobin C. Harding
0 siblings, 0 replies; 4+ messages in thread
From: Tobin C. Harding @ 2017-04-03 1:28 UTC (permalink / raw)
To: kernelnewbies
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-04-03 1:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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.