- - Problem with pointer semantics

From: Georgy Jikia <"Georgy>
Date: Tue, 20 Jun 2006 09:39:33 +0200

----boundary-LibPST-iamunique-542938503_-_-
Content-type: text/plain

On 6/20/06, Rex Couture <rex{([at]})nowhere.xy
> Thanks, Marc. I guess naming conventions (e.g., Hungarian notation)
> are indeed the state of the art. Since compilers are no help here, it
> forces the user to keep careful track of whether an array is implemented as
> a pointer or a static variable. It also occurs to me that compilers could
> easily help to keep track of this.
>
> Gérard and Wojtek, I understand perfectly why my example gives
> unexpected results. That's why I wrote it. Identical-appearing statements
> can give you very different results, depending on whether an array is static
> or dynamic. I just realized it gets worse: the results also depend on
> state.
>
> Yes, the type declaration will help you if you don't make a mistake.
> Compilers are supposed to be good at catching that kind of mistake, but in
> this case they don't. If it's not obvious by now, consider the following.
>
> VAR a, b: POINTER TO ARRAY OF INTEGER;
>
> PROCEDURE DoSomething;
> BEGIN
> b[1] := 1;
> IF something THEN
> b := a END:
> b[1] := 1;
> END DoSomething;
>
> In general, the results of b[1] := 1 cannot be determined at compile time.
> We don't even know whether the other b[1] := 1 statement does the same
> thing!
>
> Now if you happen to have another procedure:
>
> PROCEDURE DoSomethingElse;
> BEGIN b := .... END DoSomethingElse;
>
> you're cooked. The results are likely to be unpredictable, and the
> nightmarish side effects may extend to variable a -- and all because maybe
> you forgot whether a and b are static or dynamic.
>
> After thinking about it some more, if I were designing a language, I
> think I might forbid assigning a pointer except with a predefined procedure.
> For example:
>
> VAR a, b: POINTER TO ARRAY OF INTEGER;
> ...
> b := a; (* forbidden *)
> ASSIGN (b, a); (* allowed *)
>
> That is certainly one way of alerting you to a dynamic array and keeping you
> from making a pointer assignment by mistake. I haven't thought much about
> it, but I don't see any obvious problem with it.
>
> Frankly, I don't much like one variable inadvertently being aliased
> to another. Wouldn't it be nice if we didn't have to remember whether an
> array is implemented as a pointer or a static variable? Too bad compilers
> don't keep track of this sort of thing.
>
> I was hoping someone had some sort of magic. Since they don't, I'm
> sticking to old-fashioned Hungarian notation.
>
> Rex Couture
>
> --- BlackBox
> --- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy
>
>

--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy



----boundary-LibPST-iamunique-542938503_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzc1xmY2hhcnNldDAgQXJpYWw7fQ0Ke1xmMVxmbW9kZXJuIENvdXJpZXIgTmV3O30NCntcZjJc
Zm5pbFxmY2hhcnNldDIgU3ltYm9sO30NCntcZjNcZm1vZGVyblxmY2hhcnNldDAgQ291cmllciBO
ZXc7fX0NCntcY29sb3J0YmxccmVkMFxncmVlbjBcYmx1ZTA7XHJlZDBcZ3JlZW4wXGJsdWUyNTU7
fQ0KXHVjMVxwYXJkXHBsYWluXGRlZnRhYjM2MCBcZjBcZnMyMCBPbiA2LzIwLzA2LCBSZXggQ291
dHVyZSA8cmV4QGxldmVlLnd1c3RsLmVkdT4gd3JvdGU6XHBhcg0KPiAgICAgICAgIFRoYW5rcywg
TWFyYy4gIEkgZ3Vlc3MgbmFtaW5nIGNvbnZlbnRpb25zIChlLmcuLCBIdW5nYXJpYW4gbm90YXRp
b24pXHBhcg0KPiBhcmUgaW5kZWVkIHRoZSBzdGF0ZSBvZiB0aGUgYXJ0LiAgU2luY2UgY29tcGls
ZXJzIGFyZSBubyBoZWxwIGhlcmUsIGl0XHBhcg0KPiBmb3JjZXMgdGhlIHVzZXIgdG8ga2VlcCBj
YXJlZnVsIHRyYWNrIG9mIHdoZXRoZXIgYW4gYXJyYXkgaXMgaW1wbGVtZW50ZWQgYXNccGFyDQo+
IGEgcG9pbnRlciBvciBhIHN0YXRpYyB2YXJpYWJsZS4gIEl0IGFsc28gb2NjdXJzIHRvIG1lIHRo
YXQgY29tcGlsZXJzIGNvdWx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xwYXINCj4gc3RpY2tp
bmcgdG8gb2xkLWZhc2hpb25lZCBIdW5nYXJpYW4gbm90YXRpb24uXHBhcg0KPlxwYXINCj4gUmV4
IENvdXR1cmVccGFyDQo+XHBhcg0KPiAtLS0gQmxhY2tCb3hccGFyDQo+IC0tLSBzZW5kIHN1Ympl
Y3QgSEVMUCBvciBVTlNVQlNDUklCRSB0byBibGFja2JveEBvYmVyb24uY2hccGFyDQo+XHBhcg0K
PlxwYXINClxwYXINCi0tLSBCbGFja0JveFxwYXINCi0tLSBzZW5kIHN1YmplY3QgSEVMUCBvciBV
TlNVQlNDUklCRSB0byBibGFja2JveEBvYmVyb24uY2hccGFyDQpccGFyDQp9


----boundary-LibPST-iamunique-542938503_-_---
Received on Tue Jun 20 2006 - 09:39:33 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:27:50 UTC