On Tuesday, June 28, 2011 09:29:49 Jie Zhang wrote:
> On Mon, Jun 27, 2011 at 6:33 PM, Mike Frysinger wrote:
> > On Monday, June 27, 2011 18:21:31 Jie Zhang wrote:
> >> On Mon, Jun 27, 2011 at 5:45 PM, Mike Frysinger wrote:
> >> > On Friday, June 24, 2011 10:39:29 Jie Zhang wrote:
> >> >> On Fri, Jun 17, 2011 at 4:39 PM, Mike Frysinger wrote:
> >> >> > On Friday, June 17, 2011 16:09:47 Jie Zhang wrote:
> >> >> >> On Fri, Jun 17, 2011 at 1:58 PM, Mike Frysinger wrote:
> >> >> >> >> +    const char *ex_short = "[firmware=FILE]";
> >> >> >> >> +    const char *ex_desc = "FILE       Upgrade the ICE
> >> >> >> > 
> >> >> >> > const char foo[] = "..."
> >> >> >> 
> >> >> >> Why?
> >> >> > 
> >> >> > one less pointer.  compare the assembly output:
> >> >> > $ echo 'const char foo[] = "asdf";' | gcc -S -o - -x c -
> >> >> > $ echo 'const char *foo = "asdf";' | gcc -S -o - -x c -
> >> >> 
> >> >> But when it's passed as an argument, the former will pass the whole
> >> >> string but the latter will only pass a pointer.
> >> > 
> >> > no it wont.  in both cases, passing it as an argument will pass a
> >> > pointer.
> >> 
> >> On x86_64-linux-gnu host with -O2, the former:
> >
> > it's simply using the stack as temporary storage.  it isnt passing it to
> > the func.  i guess you'd also need "static" to make it use .rodata.
> 
> Yes adding "static" makes the code looks same as just using pointer.
> Then why not just using pointer?

that's fine

> Anyway what you pointed out with this example
> 
> >> >> > $ echo 'const char foo[] = "asdf";' | gcc -S -o - -x c -
> >> >> > $ echo 'const char *foo = "asdf";' | gcc -S -o - -x c -
> > 
> > one less pointer.
> 
> does not hold when "foo" is defined in a function.

right, when it isnt marked static.  most of the time, i deal with 
global/static data, hence i'm used to the foo[] optimization.
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
UrJTAG-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/urjtag-development

Reply via email to