Re: RFC: String cleanup

On Fri, 2005-12-16 at 16:49, Xavier Bestel wrote:
> On Fri, 2005-12-16 at 16:37, Benoît Dejean wrote:

> > compile something with */[] : i get exactly the same asm output
> I don't.
> In both cases the string is sotred in .rodata, but in the * case I have
> a pointer in .data (and access goes through that pointer).


static const char *str1 = "azerty";
static const char str2[] = "azerty";
void f(const char *x);
void try(void)

=> str2 is a straight char array
        .string "azerty"

=> str1 is a pointer to a char array
        .string "azerty"
        .long   .LC0

=> the code for f(str1) dereferences a pointer
        movl    str1, %eax
        pushl   %eax
        call    f

=> the code for f(str2) just computes an adress
        movl    $str2, (%esp)
        call    f

compiled with gcc 4.0.3, with -O2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]