www.digitalmars.com         C & C++   DMDScript  

D - Static vs. dynamic arrays

reply tony aplawrence.com writes:
I saw the Slashdot article, visited the web site, and was interested enough to
download the Linux compiler and start playing.

Right away, I ran into confusion:  dynamic arrays don't work like static arrays.
For example, I can do:

char [] s3="ABCDEFGH";
char [5] s4="01234";
//...
s4[0..2]=s3[0..2];

but not

char [] s3="ABCDEFGH";
char [] s4="01234";
//...
s4[0..2]=s3[0..2];

Seeems wrong to me to have types that seem identical when you see them in code
but in fact aren't??  

One of the advantages listed at http://www.digitalmars.com/d/sdwest/index.html
is "removal of special cases".  Sure looks like a special case to me, and one
the compiler isn't even aware of: the code complils, but seg faults.

I'm still playing; there's enough good stuff here that I'm not turned off.  This
is just a minor gripe, or I stupidly missed something obvious.
Apr 19 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
tony aplawrence.com wrote:

I saw the Slashdot article, visited the web site, and was interested enough to
download the Linux compiler and start playing.

Right away, I ran into confusion:  dynamic arrays don't work like static arrays.
For example, I can do:
  

(you can't do operations on them yet either). With things like this, I think the programmer should be able to do what they expect to be able to do. I've a feeling (and hoping) that Walter will fix these up before 1.0. -- -Anderson: http://badmama.com.au/~anderson/
Apr 19 2004
prev sibling parent Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
I tried it on Linux, and got a segfault.  Looks like a bug to me.

Russ

tony aplawrence.com wrote:
 I saw the Slashdot article, visited the web site, and was interested enough to
 download the Linux compiler and start playing.
 
 Right away, I ran into confusion:  dynamic arrays don't work like static
arrays.
 For example, I can do:
 
 char [] s3="ABCDEFGH";
 char [5] s4="01234";
 //...
 s4[0..2]=s3[0..2];
 
 but not
 
 char [] s3="ABCDEFGH";
 char [] s4="01234";
 //...
 s4[0..2]=s3[0..2];
 
 Seeems wrong to me to have types that seem identical when you see them in code
 but in fact aren't??  
 
 One of the advantages listed at http://www.digitalmars.com/d/sdwest/index.html
 is "removal of special cases".  Sure looks like a special case to me, and one
 the compiler isn't even aware of: the code complils, but seg faults.
 
 I'm still playing; there's enough good stuff here that I'm not turned off. 
This
 is just a minor gripe, or I stupidly missed something obvious.

Apr 19 2004