From: Felix Oxley Date: Tue, 11 Oct 2005 21:07:07 +0000 Subject: [KJ] Re: Fixing: char *foo = "blah"; Message-Id: <200510112207.09190.lkml@oxley.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="===============76527243285760171==" List-Id: To: kernel-janitors@vger.kernel.org This is a multi-part message in MIME format... --===============76527243285760171== Content-Type: multipart/alternative; boundary="----------=_1129064973-30962-133" Content-Transfer-Encoding: binary MIME-Version: 1.0 X-Mailer: MIME-tools 5.411 (Entity 5.404) This is a multi-part message in MIME format... ------------=_1129064973-30962-133 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Friday 07 October 2005 12:34, you wrote: Hi, I am nearly ready to submit a patch for this. I have done the code modifications, the test of the basic principle and am currently comparing the size of the kernel (make allyesconfig) before and after the patch. I will submit the whole lot in 12 hours. However I have a couple of queries. First, here are my own answers to the questions I submitted previously to which I received no response :-( (Ricardo did reply, but didn't answer my questions) Here is a reminder of the TODO list task: > > From: Jeff Garzik > > > > 1) The string form > > > > [const] char *foo = "blah"; > > > > creates two variables in the final assembly output, a static string, and > > a char pointer to the static string. The alternate string form > > > > [const] char foo[] = "blah"; > > > > is better because it declares a single variable. > > > > For variables marked __initdata, the "*foo" form causes only the > > pointer, not the string itself, to be dropped from the kernel image, > > which is a bug. Using the "foo[]" form with regular 'ole local > > variables also makes the assembly shorter. My question were: > 1. I presume that the [brackets] indicate that const is optional. > Therefore the following needs correcting: > char *foo = "blah"; Yes > 2. I suppose that the following form would also need correcting: > static const char *foo = "blah" Yes > > 3. Does the following (with an empty string) need correcting? > [const] char *foo = ""; > Yes (?) > 4. What about this? > static const char *class_name[] = { "off","UBR","CBR","VBR","ABR" }; No > 5. These changes are spread across the kernel code. > Do patches need to be submitted to individual subsystem maintainers, or > will a single patch be ok? ** Please answer this one for me. ** ==== But I have one more question. In certain places we have the following code: (e.g. scripts/pnmtologo.c or arch/ppc/platforms/chrp_setup.c) static const char *foo = "ABC"; int main(int argc, char *argv[]) { foo = "some other value"; } How can this be allowed? foo has been declared constant and yet is being assigned a new value ??!! My problem is that if you declare foo[] instead the code does not compile !!!!!! This has a major effect of the validity of my patch/this fix. :-( A similar question arises in the case of: const char *foo = ""; There would be no point in declaring a constant empty string so it must be given a new value elsewhere in the code. I hope somebody can explain this to me. regards, Felix ------------=_1129064973-30962-133 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline

On Friday 07 October 2005 12:34, you wrote:

Hi,

I am nearly ready to submit a patch for this.

I have done the code modifications, the test of the basic principle and am currently comparing the size of the kernel (make allyesconfig) before and after the patch.

I will submit the whole lot in 12 hours.

However I have a couple of queries.

First, here are my own answers to the questions I submitted previously to which I received no response :-(

(Ricardo did reply, but didn't answer my questions)

Here is a reminder of the TODO list task:

> > From: Jeff Garzik <jgarzik at mandrakesoft dot com>

> >

> > 1) The string form

> >

> > [const] char *foo = "blah";

> >

> > creates two variables in the final assembly output, a static string, and

> > a char pointer to the static string. The alternate string form

> >

> > [const] char foo[] = "blah";

> >

> > is better because it declares a single variable.

> >

> > For variables marked __initdata, the "*foo" form causes only the

> > pointer, not the string itself, to be dropped from the kernel image,

> > which is a bug. Using the "foo[]" form with regular 'ole local

> > variables also makes the assembly shorter.

My question were:

> 1. I presume that the [brackets] indicate that const is optional.

> Therefore the following needs correcting:

> char *foo = "blah";

Yes

> 2. I suppose that the following form would also need correcting:

> static const char *foo = "blah"

Yes

>

> 3. Does the following (with an empty string) need correcting?

> [const] char *foo = "";

>

Yes (?)

> 4. What about this?

> static const char *class_name[] = { "off","UBR","CBR","VBR","ABR" };

No

> 5. These changes are spread across the kernel code.

> Do patches need to be submitted to individual subsystem maintainers, or

> will a single patch be ok?

** Please answer this one for me. **

====

But I have one more question.

In certain places we have the following code:

(e.g. scripts/pnmtologo.c or arch/ppc/platforms/chrp_setup.c)

static const char *foo = "ABC";

int main(int argc, char *argv[])

{

foo = "some other value";

}

How can this be allowed? foo has been declared constant and yet is being assigned a new value ??!!

My problem is that if you declare foo[] instead the code does not compile !!!!!!

This has a major effect of the validity of my patch/this fix. :-(

A similar question arises in the case of: const char *foo = "";

There would be no point in declaring a constant empty string so it must be given a new value elsewhere in the code.

I hope somebody can explain this to me.

regards,

Felix

------------=_1129064973-30962-133-- --===============76527243285760171== Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline _______________________________________________ Kernel-janitors mailing list Kernel-janitors@lists.osdl.org https://lists.osdl.org/mailman/listinfo/kernel-janitors --===============76527243285760171==--