From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Generic-Package Elaboration Question / Possible GNAT Bug.
Date: Sat, 19 Nov 2011 15:36:33 -0800 (PST)
Date: 2011-11-19T15:36:33-08:00 [thread overview]
Message-ID: <4295dc09-43de-4557-a095-fc108359f27f@y42g2000yqh.googlegroups.com> (raw)
In-Reply-To: wcc4nxzu5gf.fsf@shell01.TheWorld.com
On Nov 19, 4:12 pm, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:
> Shark8 <onewingedsh...@gmail.com> 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).
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). The 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:
>
> 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
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.
next prev parent reply other threads:[~2011-11-20 0:21 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-19 21:14 Generic-Package Elaboration Question / Possible GNAT Bug Shark8
2011-11-19 22:12 ` Robert A Duff
2011-11-19 23:36 ` Shark8 [this message]
2011-11-20 9:55 ` Dmitry A. Kazakov
2011-11-21 7:25 ` AdaMagica
2011-11-21 8:43 ` Dmitry A. Kazakov
2011-11-21 10:25 ` AdaMagica
2011-11-21 13:08 ` Robert A Duff
2011-11-21 13:50 ` Dmitry A. Kazakov
2011-11-21 19:41 ` Robert A Duff
2011-11-22 8:21 ` Dmitry A. Kazakov
2011-11-21 20:40 ` J-P. Rosen
2011-11-22 8:29 ` Dmitry A. Kazakov
2011-11-22 10:25 ` Georg Bauhaus
2011-11-22 14:32 ` Dmitry A. Kazakov
2011-11-22 15:02 ` Georg Bauhaus
2011-11-22 16:23 ` Dmitry A. Kazakov
2011-11-22 17:46 ` Georg Bauhaus
2011-11-22 19:15 ` Dmitry A. Kazakov
2011-11-22 21:03 ` Randy Brukardt
2011-11-22 21:26 ` Dmitry A. Kazakov
2011-11-23 0:07 ` Georg Bauhaus
2011-11-23 8:44 ` Dmitry A. Kazakov
2011-11-23 9:32 ` Simon Wright
2011-11-23 9:56 ` Dmitry A. Kazakov
2011-11-23 11:03 ` Georg Bauhaus
2011-11-23 11:13 ` Dmitry A. Kazakov
2011-11-23 11:25 ` Georg Bauhaus
2011-11-23 13:14 ` Dmitry A. Kazakov
2011-11-23 13:59 ` Georg Bauhaus
2011-11-23 14:43 ` Dmitry A. Kazakov
2011-11-23 16:10 ` Georg Bauhaus
2011-11-23 19:51 ` Dmitry A. Kazakov
2011-11-24 0:59 ` Georg Bauhaus
2011-11-24 9:14 ` Dmitry A. Kazakov
2011-11-23 15:12 ` Simon Wright
2011-11-23 19:53 ` Dmitry A. Kazakov
2011-11-24 8:07 ` Simon Wright
2011-11-24 9:27 ` Dmitry A. Kazakov
2011-11-24 10:49 ` Georg Bauhaus
2011-11-24 13:14 ` Dmitry A. Kazakov
2011-11-24 14:31 ` Georg Bauhaus
2011-11-24 16:32 ` Dmitry A. Kazakov
2011-11-24 11:15 ` Brian Drummond
2011-11-24 18:12 ` Simon Wright
2011-11-24 23:52 ` Brian Drummond
2011-11-23 10:35 ` Brian Drummond
2011-11-23 9:54 ` Georg Bauhaus
2011-11-23 10:30 ` Dmitry A. Kazakov
2011-11-23 4:08 ` Yannick Duchêne (Hibou57)
2011-11-23 4:11 ` Yannick Duchêne (Hibou57)
2011-11-22 23:52 ` Georg Bauhaus
2011-11-23 9:04 ` Dmitry A. Kazakov
2011-11-23 11:15 ` Georg Bauhaus
2011-11-23 13:30 ` Dmitry A. Kazakov
2011-11-23 14:42 ` Georg Bauhaus
2011-11-23 19:48 ` Dmitry A. Kazakov
2011-11-24 1:36 ` Georg Bauhaus
2011-11-24 10:52 ` Dmitry A. Kazakov
2011-11-24 11:30 ` Georg Bauhaus
2011-11-24 12:52 ` Dmitry A. Kazakov
2011-11-24 14:45 ` Georg Bauhaus
2011-11-25 9:54 ` Dmitry A. Kazakov
2011-11-24 7:46 ` stefan-lucks
2011-11-24 3:07 ` Shark8
2011-11-24 6:07 ` Yannick Duchêne (Hibou57)
2011-11-24 10:10 ` Dmitry A. Kazakov
2011-11-24 11:15 ` Georg Bauhaus
2011-11-24 22:48 ` Shark8
2011-11-25 9:25 ` Yannick Duchêne (Hibou57)
2011-11-26 21:59 ` Shark8
2011-11-25 9:47 ` Dmitry A. Kazakov
2011-11-25 10:15 ` Georg Bauhaus
2011-11-25 10:51 ` Yannick Duchêne (Hibou57)
2011-11-25 15:45 ` Georg Bauhaus
2011-11-25 16:05 ` Yannick Duchêne (Hibou57)
2011-11-25 16:19 ` Yannick Duchêne (Hibou57)
2011-11-23 3:49 ` Yannick Duchêne (Hibou57)
2011-11-23 8:50 ` Georg Bauhaus
2011-11-23 9:45 ` Yannick Duchêne (Hibou57)
2011-11-23 10:55 ` Georg Bauhaus
2011-11-23 3:20 ` Yannick Duchêne (Hibou57)
2011-11-23 15:05 ` Robert A Duff
2011-11-21 17:00 ` Adam Beneschan
2011-11-23 3:13 ` Yannick Duchêne (Hibou57)
2011-11-24 3:47 ` Shark8
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox