CyberPsychotic wrote:

> ~ With
> ~ 
> ~     extern char lolo[];
> ~ 
> ~ the linker will treat the address which is associated with the symbol
> ~ `lolo' as the address of the first character in the array.
> ~ 
> ~ OTOH, with
> ~ 
> ~     extern char *lolo;
> ~ 
> ~ the linker will treat the address which is associated with the symbol
> ~ `lolo' as the address of a pointer (i.e. a 4/8 byte integer).
> 
> address of a pointer? could you clarify this. 

`char *lolo' implies an extra level of indirection. The address which
is stored in the relocation table of the .o file will be equivalent to
`&lolo', while with `char lolo[]' the address would be equivalent to
just `lolo'.

>  so in this case, it just would store in variable lolo, the address of a
> pointer, right, while, in case `char lolo[]="foobar";', it would store
> there the address of the first character in array. Hmmm.. but it doesn't
> make the difference to me.. 

Try compiling the following to assembler:

        char lolo1[] = "Hello";
        char *lolo2 = "World";

The symbol lolo1 will refer to the address of the `H' in `Hello'. The
symbol lolo2 will refer to the address of 4 bytes (on i386) of data,
which contains the address of the `W' in `World'.

> ~ Also, with `extern char *lolo', you would be able to do
> ~ 
> ~     lolo = <something>;
> ~ 
> ~ i.e. assign a different value to the pointer variable `lolo'. However,
> ~ with `extern char lolo[]', you can't do this, as `lolo' is effectively
> ~ a constant and not a variable.
> 
> ahmmm.. now it makes sence. So in my case when I had:
> 
> char foo[]="....";
> 
>  it just had a constant, foo, which pointed to a string, which contained
> "....",

Yes.

> and when I used extern char *foo; in  another code, compiler
> happily pointed foo to that place of memory, right?

The compiler assumed that foo was the address of a pointer, so it
would compile code to perform an extra level of indirection.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to