From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3dbf2f325f33ce35 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Opaque Types (was Elimination of "use" clauses) Date: 1999/07/20 Message-ID: #1/1 X-Deja-AN: 503075163 Content-Transfer-Encoding: 7bit References: <377B5807.88B875E0@cs.york.ac.uk> <7lh74s$v36$1@nnrp1.deja.com> <7ligdq$c8q$1@nnrp1.deja.com> <7ljb4e$na9$1@nnrp1.deja.com> <7ltus1$ah1@dfw-ixnews19.ix.netcom.com> <7mrjus$bet@dfw-ixnews14.ix.netcom.com> <7n0hr7$180@dfw-ixnews21.ix.netcom.com> Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Newsgroups: comp.lang.ada X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Date: 1999-07-20T00:00:00+00:00 List-Id: Richard D Riehle wrote in message news:7n0hr7$180@dfw-ixnews21.ix.netcom.com... > In article , > jerry@jvdsys.stuyts.nl wrote: > > >I am unfamiliar with the term 'opaque type', perhaps because I never looked > >at Modula-3. Can you explain what it means ? > > The second Ada example is designed as an > "opaque type". > > generic > type StackElementType is private; > Max : Positive := 100; > package Stack is > type Stack_Type is limited private; > -- declarations for push, pop, etc. > private > type Stack_Data; > type Stack is access all Stack_Data; > end Stack; > > where there is no information about the structure of the stack, > even in the private part. The details of the stack are deferred > to the package body. For example, > > package body Stack is > type Stack_Array is array(1..Max) of StackElementType; > subtype Stack_Index is range 0..Max; > type Stack_Item is record > Top : Stack_Index := 0; > Data : Stack_Array; > end record; > -- implement push, pop, etc. > end Stack; > Didn't you mean something more like the following? (The type declared in the body is not a completion of the incomplete type Stack declared in the private part). generic type StackElementType is private; Max : Positive := 100; package Stack is type Stack_Type is limited private; -- declarations for push, pop, etc. private type Stack_Item; type Stack_Type is access all Stack_Item; end Stack; package body Stack is type Stack_Array is array(1..Max) of StackElementType; subtype Stack_Index is Integer range 0 .. Max; type Stack_Item is record Top : Stack_Index := 0; Data : Stack_Array; end record; -- implement push, pop, etc. end Stack; That asked, I now have another question, or two, viz.: 1. Is the value of an opaque type worth giving up the flexibility of a discriminated type wherein the stack size does not need to be a formal parameter of the generic package, or have I missed a way to have a discriminated opaque type? 2. In a similar vein, it seems that opaque controlled types are not possible. Is this true. Perhaps a more general question is -- is there really any value in making a limited private type opaque? If so, what is that advantage? David C. Hoos, Sr.