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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbvax.ARPA Path: utzoo!linus!philabs!cmcl2!seismo!lll-crg!ucdavis!ucbvax!usc-eclb.arpa!Mailer From: Mailer@USC-ECLB.ARPA (The Mailer Daemon) Newsgroups: net.lang.ada Subject: Message of 13-Oct-85 15:46:20 Message-ID: <8510140227.AA02324@UCB-VAX> Date: Sun, 13-Oct-85 21:04:01 EDT Article-I.D.: UCB-VAX.8510140227.AA02324 Posted: Sun Oct 13 21:04:01 1985 Date-Received: Tue, 15-Oct-85 07:27:38 EDT Sender: daemon@ucbvax.ARPA Organization: The ARPA Internet List-Id: Message failed for the following: STAGER@EGLIN-VAX.ARPA.#Internet: 550 User "STAGER" Unknown. harbaughs@EGLIN-VAX.ARPA.#Internet: 550 User "harbaughs" Unknown. ------------ Return-Path: Received: from SPICE.CS.CMU.EDU (for SPICE.CS.CMU.EDU) by USC-ECLB.ARPA; Tue 1 Oct 85 09:52:11-PDT Date: 1 Oct 1985 12:50:37-EDT From: Siemens2@SPICE.CS.CMU.EDU To: INFO-ADA@ECLB ReSent-Date: Sun 13 Oct 85 15:46:20-PDT ReSent-From: INFO-ADA@USC-ECLB.ARPA ReSent-To: info-ada@USC-ECLB.ARPA ReSent-Message-ID: <12150885277.35.INFO-ADA@USC-ECLB.ARPA> I have come across what appears to be an inconsistency in Ada. Perhaps someone can explain why this is. I want to use a generic package that will manage arbitrary objects for me. It will create and destroy my objects for me and I do not care about the implementation of this package. This is easy enough to do in Ada with a generic package. Consider the following specification and ignore the fact that there is no body here. ----------------------------------------------------------------- generic type element is private; package Object_Mgr is some_generic_object: element; end Object_Mgr; ----------------------------------------------------------------- The problem I have come across occurs when trying to instantiate such a generic package where one of the actual parameters is an unconstrained type with discriminants. This is definitely illegal as stated in the LRM (section 12.3.2 or 12.3.2[4] to be more specific). I understand that I am not allowed to perform this instantiation because if there is a declaration of an object with this type in the generic, then I have defined an object which is unconstrained. This is clearly illegal in Ada. But why can't I instantiate the generic if the actual type has a default value for the discriminant? In this case all objects that I would declare in the generic package with this type would automatically be constrained by the default value given in the declaration of the actual type. What I want to know is why I can normally declare an object whose type has a discriminant with a default value, but when using generics, this property does not carry over. The following piece of code will serve to illustrate this problem. You can try and compile it if you'd like so that you can see what happens. ----------------------------------------------------------------- with Object_Mgr; procedure Test is type object (x: boolean := false) is -- Notice the default value here record case x is when true => field1: integer; when false => field2: character; end case; end record; some_object: object; -- This is OK because the discriminant has a default -- value in the type declaration package My_Object_Mgr is new Object_Mgr (element => object); -- The compiler does like this instantiation because there is a -- declaration of an object with the formal type 'element' -- in the generic package. See section 12.3.2[4] of the LRM. -- Since the actual type, 'object', has a default value, I think -- that this should not be a problem. This appears to be inconsistent -- to me. begin null; end Test; ----------------------------------------------------------------- Steve Rosen Siemens Research and Technology Laboratories Princeton, NJ USENET: {ihnp4|princeton|adrvax}!siemens!gypsy!rosen ARPA: siemens!rosen@TOPAZ -------