----boundary-LibPST-iamunique-1965117085_-_-
Content-type: text/plain
Rex Couture a écrit :
> This has to be a pretty standard problem in computer science, and it's not limited to BlackBox. Is there a good way to handle the following ambiguity? The problem is that you don't know by looking at an assignment statement what the results will be.
>
> My own method is pretty ugly: I use Hungarian notation. Please tell me there's a better way. Thanks.
>
> Rex Couture
>
> =====
> VAR
> a, b: POINTER TO ARRAY OF INTEGER;
> x, y: ARRAY 2 OF INTEGER;
>
> NEW( a, 2); NEW( b, 2);
> a[1]:= 1; b[1]:= 2;
> x[1]:= 1; y[1]:= 2;
>
> b:= a;
> y:= x; (* not an equivalent statement *)
>
> b[1]:= 5; (* a[1] = 5 *)
> y[1]:= 5; (* x[1] = 1 *)
>
What is exactly the problem?
a and b contain pointers.Assigning a to b lets the two variables contain
the same pointer and, thus, lets them point to the same array. Thus
changing b (or a) modifies the other too. On the contrary, x and y are
arrays. Assigning one to the other changes just the value of the latter,
but the two arrays remain distinct, and modifying one doesn't modify the
other.
I hope this helps.
Gérard
--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy
----boundary-LibPST-iamunique-1965117085_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzc1xmY2hhcnNldDAgQXJpYWw7fQ0Ke1xmMVxmbW9kZXJuIENvdXJpZXIgTmV3O30NCntcZjJc
Zm5pbFxmY2hhcnNldDIgU3ltYm9sO30NCntcZjNcZm1vZGVyblxmY2hhcnNldDAgQ291cmllciBO
ZXc7fX0NCntcY29sb3J0YmxccmVkMFxncmVlbjBcYmx1ZTA7XHJlZDBcZ3JlZW4wXGJsdWUyNTU7
fQ0KXHVjMVxwYXJkXHBsYWluXGRlZnRhYjM2MCBcZjBcZnMyMCBSZXggQ291dHVyZSBhIFwnZTlj
cml0IDpccGFyDQo+ICAg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