Subject: Re: CVS commit: syssrc
To: Jason R Thorpe <thorpej@zembu.com>
From: Matthew Jacob <mjacob@feral.com>
List: source-changes
Date: 12/30/2000 12:25:13
On Sat, 30 Dec 2000, Jason R Thorpe wrote:
> On Sat, Dec 30, 2000 at 11:47:53AM -0800, Matthew Jacob wrote:
>
> > Read my update. It is a bug somewher and not the code.
> >
> > char *foo = "XXX"
> >
> > is not
> >
> > const char *foo = "XXX";
>
> The Alpha compiler generates the following code for 'char *foo = "XXXX";':
>
> .globl foo
> .section .rodata
> $LC0:
> .ascii "XXXX\0"
> .data
> .align 3
> foo:
> .quad $LC0
> .ident "GCC: (GNU) egcs-2.91.66 19990314 (egcs-1.1.2 release)"
>
> ...and the same code for 'const char *foo = "XXXX";'.
>
> If you change it to 'char foo[] = "XXXX";':
>
> .globl foo
> .data
> foo:
> .ascii "XXXX\0"
> .ident "GCC: (GNU) egcs-2.91.66 19990314 (egcs-1.1.2 release)"
>
> ...and if you compile the first version with -fwritable-strings:
>
> .globl foo
> .data
> $LC0:
> .ascii "XXXX\0"
> .align 3
> foo:
> .quad $LC0
> .ident "GCC: (GNU) egcs-2.91.66 19990314 (egcs-1.1.2 release)"
>
> This is one of the subtle semantic differences between * and [].
>
[ you have an alpha again? Great! ]
Yes. It's really hard for me to shake myself from early training with C which
said that * && [] are semantically equal.
I'm certainly convinced of this now. As I said, I wouldn't have gone this
direction with the language., but that hardly matters.
-matt