www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - char arrays

reply "Saaa" <empty needmail.com> writes:
After quite a long thread in .learn here is what I learned:
(including a question :)

D1

string literal=Stored it in the code segment (read-only on unix)

char[] c=`string literal`;
char[14] c2=`string literal`;
char[] c3;    //heap: dynamic array of chars
char[10] c4;    //stack: static array(10) of chars
char[] c5=`heap: dynamic array of chars `.dup;
char[28] c6=`stack: static array(28) of chars `.dup;

char[] c7=c;    //c7 data points to the string literal of c
char[] c8=c.dup;    //c8=dynamic array of chars on heap

char[][] c9;    //heap: dynamic array of arrays of chars;
char[10][5] c10;    //stack: static array(5) of arrays(10) of chars;

char[4][5] c11=[`onee`,`twoo`,`thre`,`four`,`five`];    //string literals?
char[][] c12=[`one`,`two`,`three`,`five`,`six`];    //string literals?

This example is wrong:
char[] str;    //str is not a string literal
char[] str1 = "abc";
str[0] = 'b';        // error, "abc" is read only, may crash 
Jan 28 2008
parent "Saaa" <empty needmail.com> writes:
Please tell me I'm wrong or change the example .


 This example is wrong:
 char[] str;    //str is not a string literal
 char[] str1 = "abc";
 str[0] = 'b';        // error, "abc" is read only, may crash

I should have posted this in learn yeah ;)
 char[4][5] c11=[`onee`,`twoo`,`thre`,`four`,`five`];    //string literals?
 char[][] c12=[`one`,`two`,`three`,`five`,`six`];    //string literals? 

Jan 29 2008