string literals

Milke Wey no.spam at example.com
Mon Jan 28 09:48:26 PST 2008


On Sun, 2008-01-27 at 22:44 -0800, Robert Fraser wrote:
> Milke Wey wrote:
> > On Sat, 2008-01-26 at 15:26 -0500, bearophile wrote:
> >> Milke Wey:
> >>> On linux you would get an nice Segfault when running that code.
> >> Ah, thank you then. I have thought that's true only for string literals assigned to static arrays:
> >>
> >> void main() {
> >>     char[3] str = "abc";
> >>     str[0] = 'b';
> >> }
> >>
> >> Bye,
> >> bearophile
> > 
> > I don't know why but it actually works when using a static array.
> > 
> 
> On a UNIX system or a Windows system? It should work fine on Windows 
> anyway. Also, the static array declaration may say to the compiler 
> "allocate this on the stack"... not sure; I don't think that's speced.

On Linux with DMD 1.025.

-- 
Mike Wey



More information about the Digitalmars-d-learn mailing list