This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Char *Foo = "ABC" or Char Foo[] = "ABC"" ?


I was looking on the kernel-janitors site at the To Do list and found this 
task below, which I decided to try my hand at. 
(http://www.kerneljanitors.org/TODO)

> 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.
> 

However, I was advised by a list member that this work was of uncertain 
benefit:

> Ricardo Nabinger Sanchez wrote:
>  
> By May, 2005, I was working on this.  Alexey told me that besides what gcc
> should do, I had to confirm that the change made was actually better.
> 
> In some cases, it was not.  I've made a testcase, and the results were
> pretty odd (I was expecting something else):
> 
> http://lists.osdl.org/pipermail/kernel-janitors/2005-May/004146.html
> 
> Different versions of gcc and cross-compilers should produce different
> results.  I really don't know yet what is the best case (ie, which is good
> for (almost) all architectures/compilers).
> 
> Anyone?

Is anybody able to give me an authoritative answer about which for should be 
used?

The second part of the task was descibed thus:
> 2) "unsigned int" is preferred to "int", it generates better asm code on
> all platforms except sh5.  This replacement needs to be done manually,
> because often 'int' is required due to negative values -Exxx commonly
> passed as error values.

Can anyone comment on the accuracy of this?

Many thanks,
Felix Oxley


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]