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-Thread: 103376,ea5071f634c2ea8b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.15.105 with SMTP id w9mr11967731pbc.7.1321740769280; Sat, 19 Nov 2011 14:12:49 -0800 (PST) Path: h5ni11072pba.0!nntp.google.com!news1.google.com!newsfeed2.dallas1.level3.net!news.level3.com!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Generic-Package Elaboration Question / Possible GNAT Bug. Date: Sat, 19 Nov 2011 17:12:48 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <7bf9bc32-850a-40c6-9ae2-5254fe220533@f29g2000yqa.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 X-Trace: pcls6.std.com 1321740768 12129 192.74.137.71 (19 Nov 2011 22:12:48 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sat, 19 Nov 2011 22:12:48 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:Ao4qQKivecJT33I+JPcPMRRVCTs= Xref: news1.google.com comp.lang.ada:18980 Content-Type: text/plain; charset=us-ascii Date: 2011-11-19T17:12:48-05:00 List-Id: Shark8 writes: > I was working on some simple little array manipulation functions when > I encountered an interesting behavior in the compiler; it said that > trying to instantiate a function of the form: > Generic > Type Element is Private; > Type Index_Type is (<>); > Type Array_Type is Array (Index_Type Range <>) of Element; ... > But the question that came to my mind after reading the ARM section on > the error (sorry, I forgot to write it down) is, why is it not static? Generic formals are not static, because that would violate the generic contract model. That is, the compiler should be able to determine the legality of the generic body without knowing anything about any instantiations. In your case statement, what if the range of Index_Type were 1..1? Then 'First = 'Last, so there's a duplicate in your case statement (which would be illegal in the instance, but we're not supposed to know about the instance). In general, the design of Ada is that if a generic body is legal, then every possible instance is legal (so the compiler need not check the instances). The design of C++ templates is very different in this regard! > Is it because though the elaboration-parameters *may* be known [and > static] at compile-time that some instantiation might NOT be > [guaranteed] to be known at compile-time? (i.e. because the compiler > cannot guarantee that you won't throw 1..N where N is something pulled > from the user-input?) Yeah, that's another example. By the way, I suggest: type Index_Type is range <>; Unconstrained arrays don't make a whole lot of sense when the index type is enumeration or modular. And if you add some assertions, to require that Index_Type'First > Index_Type'Base'First, and Data'First = Index_Type'First, then you can simplify your code -- you won't need the case statement. Well, maybe you also need to assert that Data'Last < Index_Type'Base'Last. Consider using Ada 2012 preconditions and/or predicates. - Bob