Thread View: comp.lang.modula2
3 messages
3 total messages
Started by Mukesh Dalal
Sat, 05 Sep 1987 15:59
Dereferencing of opaquely exported pointers?
Author: Mukesh Dalal
Date: Sat, 05 Sep 1987 15:59
Date: Sat, 05 Sep 1987 15:59
26 lines
1056 bytes
1056 bytes
Assume that a module M1 exports a pointer type P opaquely, and a
module M2 imports P from M1 and declares a variable p of type P.
Can M2 refer to p^, new(p) and dispose(p) {allocate, or deallocate}?
i.e.,
DEFINITION M1;
TYPE P;
....
IMPLEMENTATION M2;
FROM M1 IMPORT P;
VAR p:P;
....
BEGIN
new(p);
....(p^);
...
Thanks in advance for the response.
--
Mukesh Dalal Voice: (201)-878-1763
Dept. of Computer Sc. (Rutgers) Net: dalal@topaz.rutgers.edu
Re: Dereferencing of opaquely exported pointers?
Author: David Hiebeler
Date: Tue, 08 Sep 1987 17:49
Date: Tue, 08 Sep 1987 17:49
15 lines
1429 bytes
1429 bytes
DEC's Modula-2 compiler will not dereference an opaquely declared pointer
from within an external module. (NEW() gives me a wrong parm type,
^ gives me dereference of a non-pointer). This seems logical; if the
type is opaquely defined, then one shouldn't be poking around with its
innards from another module. That's what transparent types are for.
If you wanted something which was opaque, but still allowed you to
perform those few actions, I suppose you could just export a couple of
procedures from the first module, which were simply calls to the system-
allocations procedures.
-D.H.
----
David Hiebeler hiebeler@csv.rpi.edu
Troy, NY "Illusions, Richard! Every
bit of it illusions!"
Re: Dereferencing of opaquely exported pointers?
Author: fred sullivan
Date: Tue, 08 Sep 1987 21:26
Date: Tue, 08 Sep 1987 21:26
41 lines
2858 bytes
2858 bytes
In article <14474@topaz.rutgers.edu> dalal@topaz.rutgers.edu (Mukesh Dalal) writes:
>
>Assume that a module M1 exports a pointer type P opaquely, and a
>module M2 imports P from M1 and declares a variable p of type P.
>Can M2 refer to p^, new(p) and dispose(p) {allocate, or deallocate}?
>
I certainly hope not. The implementations I've tried don't allow it. The
point of opaque types is to hide the type of a data structure from modules
which use it, allowing client modules to be independent of the particular
implementation chosen. Thus clients modules can be written before, or
concurrently with, the implementation module, and if one decides to change
the implementation, then the client module doesn't have to be rewritten.
This means that some method for initializing a variable of an opaque type
must be provided (as a procedure). I tell my data structures students to
expect to include an initialize procedure with every opaque type.
Example: consider two implementations of linear lists.
1. a list is stored as a record where one field is the length and the other
field is an array which holds the list elements. In this case,
initialization consists of allocating the record and setting the size field
to zero.
2. a list is stored as a linked list of nodes, each of which is a record,
where one field holds an element and the other field holds a link to the
next node. In this case initialization consists of setting the variable to
NIL.
If you write an initialize procedure, you can write client modules
independently of the method used.
If you want to be able to refer to p^, etc, then declare the type in the
definition module, and don't make it an opaque type.
I think that the statement "opaque type = abstract data type" in modula is a
reasonable assessment of the situation. In fact, it is for this reason that
we use modula to teach abstract data types in our data structures course.
Fred Sullivan
Department of Mathematical Sciences
State University of New York at Binghamton
Binghamton, New York 13903
Email: sullivan@marge.math.binghamton.edu
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads