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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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 Received: by 10.68.39.100 with SMTP id o4mr8521560pbk.0.1321748516754; Sat, 19 Nov 2011 16:21:56 -0800 (PST) Path: h5ni11421pba.0!nntp.google.com!news1.google.com!postnews.google.com!y42g2000yqh.googlegroups.com!not-for-mail From: Shark8 Newsgroups: comp.lang.ada Subject: Re: Generic-Package Elaboration Question / Possible GNAT Bug. Date: Sat, 19 Nov 2011 15:36:33 -0800 (PST) Organization: http://groups.google.com Message-ID: <4295dc09-43de-4557-a095-fc108359f27f@y42g2000yqh.googlegroups.com> References: <7bf9bc32-850a-40c6-9ae2-5254fe220533@f29g2000yqa.googlegroups.com> NNTP-Posting-Host: 24.230.151.194 Mime-Version: 1.0 X-Trace: posting.google.com 1321748516 21609 127.0.0.1 (20 Nov 2011 00:21:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 20 Nov 2011 00:21:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: y42g2000yqh.googlegroups.com; posting-host=24.230.151.194; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESNKRC X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0,gzip(gfe) Xref: news1.google.com comp.lang.ada:18981 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2011-11-19T15:36:33-08:00 List-Id: On Nov 19, 4:12=A0pm, Robert A Duff wrote: > 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: > > =A0 =A0Generic > > =A0 =A0 =A0 Type Element is Private; > > =A0 =A0 =A0 Type Index_Type is (<>); > > =A0 =A0 =A0 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. =A0That 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 =3D '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). Oh, good point! I hadn't even considered that. > 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). =A0The design of C++ templates is very different > in this regard! *nod* -- I understand that Ada's generics are quite different than C+ +'s templates. Some of the reasons I've come across make a whole lot more sense to me for the Ada model than the C++, this "every possible instance" restriction is one such case. Who would want a system where a 'general' feature only worked for *some* instances. {Meaning the general feature wasn't actually .} > By the way, I suggest: > > =A0 =A0 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 =3D 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 I'm looking forward to the Ada 2012 version, though as this post indicates I still have a bit of a way to go to really *understand* even the base of the language; I'm enjoying 'playing' with the language, though the slow-going on getting that fuller understanding can be frustrating. (I'm still a complete 'noob' when it comes to tasking, though that's one of the more intriguing portions of the language.) Thanks for the help/reply.