🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.oberon
Article #1305

Re: The Trouble with WITH...

#1305
From: Stefan Ludwig
Date: Wed, 10 Apr 1996 07:46
72 lines
2268 bytes
In article <318BAE1B.443@iis.nsk.su>, Alex Nedorya  <ned@iis.nsk.su> wrote:
>Stefan Ludwig wrote:
>> I strongly advocate dropping WITH on pointers in commercial compilers.
>> It's a hole in the type system, and it needs to be plugged!
>
>XDS Oberon-2 (starting from v2.12) reports an error if the value of
>pointer may be changed inside WITH, like in 
>
>TYPE 
>  P = POINTER TO R;
>  R = RECORD i: INTEGER END;
>  P1 = POINTER TO R1;
>  R1 = RECORD (R) n: INTEGER END;
>
>PROCEDURE proc1(p: P);
>  PROCEDURE proc2;
>  BEGIN
>    p:=NIL;
>  END proc2;
>BEGIN
>  WITH p: P1 DO
>    proc2;
>  END;
>END proc1;
>
>I think it is better solution then dropping WITH on pointers.
>
>-- Alex

You cannot check this for all cases! It's not safe. Consider the following:

MODULE A;
	VAR p*: Pointer;
END A.

MODULE B;
	IMPORT A;
	PROCEDURE Change*;
	BEGIN NEW(A.p)
	END Change;
END B.

MODULE C;
	IMPORT A, B;
	...
	PROCEDURE Crash*;
	BEGIN
		WITH A.p: Extension DO
			B.Change;
			do something with A.p.extendedField ... uh oh!
		END
	END Crash;
END C.

I agree, it's a pathological case, but most of the time, it's those
pathological cases that get you!

In the example above, unless you do global system analysis, you cannot find
an inconsistency (unless you're conservative and flag everything that might
change the WITH'ed pointer). IMHO, dropping WITH on pointers is the better
solution and much more readable as well...

Regards,

  Stefan H-M Ludwig              mailto:ludwig@inf.ethz.ch
                                 http://www-cs.inf.ethz.ch/~ludwig
  Institute for Computer Systems
  Swiss Federal Institute of Technology (ETH)
  CH-8092 Zurich, Switzerland

  Phone: 41-1-632 7301
  Fax  : 41-1-632 1307
Technical Details
Message-ID: <4kfp0v$213@lillian.inf.ethz.ch>
Path: arc1-ca.pugleaf.net!inf.ethz.ch!not-for-mail
References: <2251891AH0002BF21H@p.froehlich.amc.cube.net> <4jv1c1$drh@artemis.it.luc.edu> <4jvvs3$93h@lillian.inf.ethz.ch> <318BAE1B.443@iis.nsk.su>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!inf.ethz.ch!not-for-mail
From: ludwig@inf.ethz.ch (Stefan Ludwig)
Newsgroups: comp.lang.oberon
Subject: Re: The Trouble with WITH...
Date: 10 Apr 1996 09:46:39 +0200
Organization: Dept. Informatik, Swiss Federal Institute of Technology
Message-ID: <4kfp0v$213@lillian.inf.ethz.ch>
References: <2251891AH0002BF21H@p.froehlich.amc.cube.net> <4jv1c1$drh@artemis.it.luc.edu> <4jvvs3$93h@lillian.inf.ethz.ch> <318BAE1B.443@iis.nsk.su>
NNTP-Posting-Host: lillian.inf.ethz.ch