🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #3812

Re: Dereferencing of opaquely exported pointers?

#3812
From: fred sullivan
Date: Tue, 08 Sep 1987 21:26
41 lines
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
Technical Details
Message-ID: <693@bingvaxu.cc.binghamton.edu>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!rutgers!sunybcs!bingvaxu!marge.math.binghamton.edu!sullivan
References: <14474@topaz.rutgers.edu>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!rutgers!sunybcs!bingvaxu!marge.math.binghamton.edu!sullivan
From: sullivan@marge.math.binghamton.edu (fred sullivan)
Newsgroups: comp.lang.modula2
Subject: Re: Dereferencing of opaquely exported pointers?
Message-ID: <693@bingvaxu.cc.binghamton.edu>
Date: Tue, 8-Sep-87 17:26:17 EDT
Article-I.D.: bingvaxu.693
Posted: Tue Sep  8 17:26:17 1987
Date-Received: Wed, 9-Sep-87 06:47:10 EDT
References: <14474@topaz.rutgers.edu>
Sender: news@bingvaxu.cc.binghamton.edu
Reply-To: sullivan@marge.math.binghamton.edu (fred sullivan)
Organization: Department of Mathematical Sciences, SUNY-Binghamton
Lines: 41
Keywords: Dereferencing,pointers.