Article View: comp.lang.oberon
Article #850NEW(p)
From: Bronxx
Date: Fri, 26 Jan 1996 13:16
Date: Fri, 26 Jan 1996 13:16
70 lines
2555 bytes
2555 bytes
NEW(p)
~~~~~~
I have problems with this creation of pointers (as I mentioned in
an earlier post, this is because of many errors in the book about
Oberon by M. Reiser and N. Wirth, even if it is a very good book,
I'm disappointed about the chapter "pointers").
But basically, a pointer doesn't exist if it's not created with
a NEW(p) (p:P is declared by VAR or TYPE as a POINTER TO basetype)
Allright, let's start with what I know:
The declaration of a pointer does not produce the variable it points to.
We have to generate the variable explicitly by NEW(p), where the actual
parameter p is a pointer of type P. NEW(p) creates a variable that is
an instance of the base type of P. The pointer p is initialized such that
it points to that instance.
That means we have to create each pointer with NEW(p) before we can
work with it.
For example
TYPE P = POINTER TO PDesc;
PDesc = RECORD key: Key; next: P END;
VAR p:P;
What about the p.next then? It is a pointer too, does it have to
be created with NEW() as well? I guess not. What is it's value? NIL?
Before we can assign something to p or p.next, we have to create this
with NEW(), right?
Because there is no such thing as a "spontaneous pointer", it doesn't
exist before we create it with NEW().
Therefore we have to produce each node (e.g. of a list) with NEW(node),
before we add it to the list.
My problem seems to be too many NEW instruction (because I think we have to create every pointer). Please help me here:
(Let "first:P" be a pointer that provides a link to the first list node.)
An example of a "removal of the first node of a list" is:
PROCEDURE FirstNode(VAR first: P):P;
VAR n: P;
BEGIN
n := first;
IF n # NIL THEN first := n.next END;
RETURN n
END FirstNode;
My questions now:
* Why can we assign something to n without a NEW(n) statement?
* Why is there no NEW(n) at all?
I assume because we did VAR n:P and first exists as a variable
parameter.
Please mail your suggestions to rmichl@cinenet.ch or post here.
Thanxx,
Robert
%%% http://amiga.icu.net.ch/~rmichl %% rmichl@cinenet.ch %%%
%% Robert Michl %% Fabrikstrasse 21 %% 8005 Zuerich %% CH %%
Technical Details
Message-ID:
<4eak7d$nm5@neptune.ethz.ch>Path:
arc1-ca.pugleaf.net!inf.ethz.ch!rmichlShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!inf.ethz.ch!rmichl From: rmichl@iiic.ethz.ch (Bronxx) Newsgroups: comp.lang.oberon Subject: NEW(p) Date: 26 Jan 1996 13:16:29 GMT Organization: Dept. Informatik, Swiss Federal Institute of Technology (ETH), Zurich, CH Message-ID: <4eak7d$nm5@neptune.ethz.ch> NNTP-Posting-Host: raf1.inf.ethz.ch Keywords: pointer