comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Generic formal access types
Date: 02 May 2003 12:57:46 -0400
Date: 2003-05-02T12:57:46-04:00	[thread overview]
Message-ID: <wccof2lqoad.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: gTwsa.441952$OV.431849@rwcrnsc54

tmoran@acm.org writes:

> Why not
>  declare
>      package Instance is new Generic_Package (Integer);
>      subtype Ptr is Instance.Node_Content_Ptr;
>      P : Ptr;

That works only if you want to declare the pointer type at the same
place where the instantiation is.  In many cases, you don't.  For this
reason, it's almost always better to pass the pointer type into
generics.

When I invented the Address_To_Access_Conversions package (see chap 13),
I made the mistake of declaring the pointer type inside the generic,
because I thought the primary use would be peek/poke functionality, so
you would always say ".all" right away.  And it makes the instantiation
simpler.  But it turns out to be a pain.

The "right" solution to the OP's problem is to pass in the designated
type and the pointer type.  Yes, that requires an extra line of code at
the instantiation.  But I don't think there's a better solution.

- Bob



  reply	other threads:[~2003-05-02 16:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-30 18:30 Generic formal access types 
2003-04-30 19:27 ` Simon Wright
2003-05-01  8:58   ` 
2003-04-30 21:42 ` Chad R. Meiners
2003-05-01  9:06   ` 
2003-05-01  9:58     ` Martin Krischik
2003-05-01 13:00       ` 
2003-05-02  9:14         ` Ludovic Brenta
2003-05-02 10:43           ` 
2003-05-02 10:50             ` 
2003-05-01 10:09     ` 
2003-05-02  1:14 ` tmoran
2003-05-02  9:52   ` 
2003-05-02 16:18     ` tmoran
2003-05-02 16:57       ` Robert A Duff [this message]
2003-05-02 19:39         ` Randy Brukardt
2003-05-05  8:14         ` 
2003-05-05 16:40         ` Matthew Heaney
2003-05-05 17:34           ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox