From: Mateusz Guzik Subject: Re: [PATCH] fs: Cleanup string initializations (char[] instead of char *) Date: Sat, 17 May 2014 17:44:28 +0200 Message-ID: <20140517154427.GB1939@mguzik.redhat.com> References: <1400338818-2853-1-git-send-email-manuel.schoelling@gmx.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org To: Manuel =?utf-8?Q?Sch=C3=B6lling?= Return-path: Content-Disposition: inline In-Reply-To: <1400338818-2853-1-git-send-email-manuel.schoelling@gmx.de> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Sat, May 17, 2014 at 05:00:18PM +0200, Manuel Sch=C3=B6lling wrote: > Initializations like 'char *foo =3D "bar"' will create two variables:= a static > string and a pointer (foo) to that static string. Instead 'char foo[]= =3D "bar"' > will declare a single variable and will end up in shorter > assembly (according to Jeff Garzik on the KernelJanitor's TODO list). >=20 This is a greatly oversimplifying things, this may or may not happen. Out of curiosity I checked my kernel on x86-64 and it has this optimized: 0xffffffffa00a9629 : movabs $0x203a7367616c66,%rcx crash> ascii 0x203a7367616c66 00203a7367616c66: flags: > fs/binfmt_misc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c > index b605003..2a10529 100644 > --- a/fs/binfmt_misc.c > +++ b/fs/binfmt_misc.c > @@ -419,7 +419,7 @@ static void entry_status(Node *e, char *page) > { > char *dp; > char *status =3D "disabled"; > - const char * flags =3D "flags: "; > + const char flags[] =3D "flags: "; > =20 > if (test_bit(Enabled, &e->flags)) > status =3D "enabled"; This particular function would be better of with removing this variable and replacing all pairs like: sprintf(dp, ...); dp +=3D strlen(...) with: dp +=3D sprintf(dp, ...); --=20 Mateusz Guzik