[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7a12fd4599758b8cd5fd376db6c9a950d2ed2094.camel@perches.com>
Date: Sun, 20 Mar 2022 10:36:22 -0700
From: Joe Perches <joe@...ches.com>
To: Sebastian Gottschall <s.gottschall@...media-net.de>,
John Crispin <john@...ozen.org>, trix@...hat.com, toke@...e.dk,
kvalo@...nel.org, davem@...emloft.net, kuba@...nel.org,
pabeni@...hat.com
Cc: linux-wireless@...r.kernel.org, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] ath9k: initialize arrays at compile time
On Sun, 2022-03-20 at 18:17 +0100, Sebastian Gottschall wrote:
> Am 20.03.2022 um 17:48 schrieb John Crispin:
> >
> >
> > On 20.03.22 16:20, trix@...hat.com wrote:
> > > array[size] = { 0 };
> >
> > should this not be array[size] = { }; ?!
> >
> > If I recall correctly { 0 } will only set the first element of the
> > struct/array to 0 and leave random data in all others elements
> >
> > John
>
> You are right, john
No. The patch is fine.
Though generally the newer code in the kernel uses
type dec[size] = {};
to initialize stack arrays.
array stack declarations not using 0
$ git grep -P '^\t(?:\w++\s*){1,2}\[\s*\w+\s*\]\s*=\s*\{\s*\};' -- '*.c' | wc -l
213
array stack declarations using 0
$ git grep -P '^\t(?:\w++\s*){1,2}\[\s*\w+\s*\]\s*=\s*\{\s*0\s*\};' -- '*.c' | wc -l
776
Refer to the c standard section on initialization 6.7.8 subsections 19 and 21
19
The initialization shall occur in initializer list order, each initializer provided for a
particular subobject overriding any previously listed initializer for the same subobject
all subobjects that are not initialized explicitly shall be initialized implicitly the same as
objects that have static storage duration.
...
21
If there are fewer initializers in a brace-enclosed list than there are elements or members
of an aggregate, or fewer characters in a string literal used to initialize an array of known
size than there are elements in the array, the remainder of the aggregate shall be
initialized implicitly the same as objects that have static storage duration.
Powered by blists - more mailing lists