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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,927ae253da8bb547 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-01 12:53:53 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Specialization Date: 01 Jun 2002 15:50:10 -0400 Organization: NASA Goddard Space Flight Center (skates.gsfc.nasa.gov) Message-ID: References: <4519e058.0205300909.5bfb317d@posting.google.com> NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 1022961454 4131 128.183.220.71 (1 Jun 2002 19:57:34 GMT) X-Complaints-To: usenet@news.gsfc.nasa.gov NNTP-Posting-Date: 1 Jun 2002 19:57:34 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:25173 Date: 2002-06-01T19:57:34+00:00 List-Id: Simon Wright writes: > Stephen Leake writes: > > > You could actually give it a default, but the users would have to make > > that object visible, and use your name for it; not much better than > > simply supplying the parameter at instantiation. > > I don't think so, it's their type not mine Hmm. You seem to be correct. I was mislead by ARM 12.4: 2. formal_object_declaration ::= defining_identifier_list : mode subtype_mark [:= default_expression]; *Name Resolution Rules* 3. The expected type for the default_expression, if any, of a formal object is the type of the formal object. I assumed the 'default_expression' was resolved at the point of instantiation, not at the point of declaration of the generic. But I now see that doesn't make sense. Learn something new every day :). Here's code to prove your point. It fails because 'A_Null_Value' is not visible at it's first occurance. with Ada.Text_IO; use Ada.Text_IO; procedure Formal_Default is type My_Type is record Foo : Integer; end record; generic type Gen_Type is private; Null_Value : in Gen_Type := A_Null_Value; -- wrong; not visible. with function Image (Item : in Gen_Type) return String is <>; procedure Gen_Bar; procedure Gen_Bar is begin Put_Line (Image (Null_Value)); end Gen_Bar; function Image (Item : in My_Type) return String is begin return Integer'Image (Item.Foo); end Image; A_Null_Value : constant My_Type := (Foo => 0); procedure Bar is new Gen_Bar (My_Type); begin Bar; end Formal_Default; -- -- Stephe