about array setting
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Fri Jan 19 22:17:46 PST 2007
dfun wrote:
> about array setting
> on this page http://www.digitalmars.com/d/arrays.html
> give an example
>
> int[3] s;
> int* p;
> s[] = 3; // same as s[0] = 3, s[1] = 3, s[2] = 3
> p[0..2] = 3; // same as p[0] = 3, p[1] = 3
>
> pring error => Error: Access Violation
> why?
> use dmd 1.0
Because 'p' doesn't actually point to anything. It is an incomplete example (one which
assumes users will fill in the details). Try something like the following:
<code>
int[3] s ;
int* p ;
s[] = 3; // same as s[0] = 3, s[1] = 3, s[2] = 3
p = s.ptr;
p[0 .. 2] = 1; // same as p[0] = 1, p[1] = 1
// and, in this case, s[0] = 1, s[1] = 1
</code>
-- Chris Nicholson-Sauls
More information about the Digitalmars-d
mailing list