Thread overview | |||||
---|---|---|---|---|---|
|
April 24, 2005 Segfault from changing a string | ||||
---|---|---|---|---|
| ||||
The following segfaults on Linux dmd - should it? char[] test = "this is a test".dup; is OK int main(char[][] args) { char[] test = "this is a test"; test[0] = 'T'; return 0; } Brad |
April 24, 2005 Re: Segfault from changing a string | ||||
---|---|---|---|---|
| ||||
Posted in reply to brad beveridge | brad beveridge wrote: > The following segfaults on Linux dmd - should it? Yes, as it has read-only str literals... This is mentioned in the very small print on the site: http://www.digitalmars.com/d/dcompiler.html#linux "Differences from Win32 version * String literals are read-only. Attempting to write to them will cause a segment violation. * The configuration file is /etc/dmd.conf" > char[] test = "this is a test".dup; is OK This is the "correct" D code to use... Strings should use Copy-On-Write (COW) This second way will work with GDC too. --anders |
April 24, 2005 Re: Segfault from changing a string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | > This is mentioned in the very small print on the site:
>
> http://www.digitalmars.com/d/dcompiler.html#linux
> "Differences from Win32 version
> * String literals are read-only. Attempting to write to
> them will cause a segment violation.
> * The configuration file is /etc/dmd.conf"
>
>> char[] test = "this is a test".dup; is OK
>
>
> This is the "correct" D code to use...
> Strings should use Copy-On-Write (COW)
>
> This second way will work with GDC too.
>
> --anders
Ah, that fine print does look familiar, but it's been a while since I read the whole D spec :)
Thank you Anders
Brad
|
Copyright © 1999-2021 by the D Language Foundation