digitalmars.D.bugs - Segfault from changing a string
- brad beveridge (9/9) Apr 24 2005 The following segfaults on Linux dmd - should it?
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (12/14) Apr 24 2005 Yes, as it has read-only str literals...
- brad beveridge (4/21) Apr 24 2005 Ah, that fine print does look familiar, but it's been a while since I
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
Apr 24 2005
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 OKThis is the "correct" D code to use... Strings should use Copy-On-Write (COW) This second way will work with GDC too. --anders
Apr 24 2005
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"Ah, that fine print does look familiar, but it's been a while since I read the whole D spec :) Thank you Anders Bradchar[] test = "this is a test".dup; is OKThis is the "correct" D code to use... Strings should use Copy-On-Write (COW) This second way will work with GDC too. --anders
Apr 24 2005








brad beveridge <brad nowhere.com>