Fixing: char *foo = "blah";
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:
Quoted 9 lines
Quoted 9 lines
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
Quoted 8 lines
Quoted 8 lines
[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:
Quoted 3 lines
1. I presume that the [brackets] indicate that const is optional.
Therefore the following needs correcting: char *foo = "blah";
Yes
Quoted 2 lines
2. I suppose that the following form would also need correcting:
static const char *foo = "blah"
Yes
Quoted 4 lines
3. Does the following (with an empty string) need correcting?
[const] char *foo = "";
Yes (?)
Quoted 2 lines
4. What about this?
static const char *class_name[] = { "off","UBR","CBR","VBR","ABR" };
No
Quoted 3 lines
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
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors