comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Universal type in Ada
Date: Thu, 16 Jun 2005 13:59:43 +0200
Date: 2005-06-16T13:59:43+02:00	[thread overview]
Message-ID: <a3gytn0gjusp$.1kgj4kfixqylc.dlg@40tude.net> (raw)
In-Reply-To: wvbroea61zq3.fsf@sun.com

On 16 Jun 2005 10:18:44 +0200, Ole-Hjalmar Kristensen wrote:

> Please do not do this. As someone (may have been John Max Skaller) on
> comp.lang.c++ said once, "casting is something you do when fishing".
> Think about what you are trying to do, and try to figure out how this
> can be accomplished by the tools available to you in Ada, like
> generics or run-time polymorphism.

Yes, but unfortunately, there is one case in Ada 95 where apparently
unnecessary downcasting is necessary: pool-specific access types to
class-wide objects:

type Object is tagged ...;
type Object_Ptr is access Object'Class;

function Create_My_Object (...) return Object_Ptr is
   Result  : Object_Ptr;
begin
   Result := new My_Object (...);
   declare
      This : My_Object renames  M_Object (Result.all);
         -- Casting is required because a pool-specific access
         -- to My_Object is not convertible to a pool-specific
         -- access to Object'Class!
   begin
      -- Do whatever needed to complete initialization of
      -- This
      ...
   end;
   return Result;
end Create_My_Object;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2005-06-16 11:59 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-15 13:07 Universal type in Ada zw
2005-06-15 13:32 ` Larry Kilgallen
2005-06-16 13:13   ` zw
2005-06-16 14:36     ` Preben Randhol
2005-06-17  2:54     ` Stephen Leake
2005-06-19 17:38     ` Martin Krischik
2005-06-15 13:55 ` Dmitry A. Kazakov
2005-06-15 14:37   ` Preben Randhol
2005-06-15 16:48     ` Dmitry A. Kazakov
2005-06-15 14:34 ` Preben Randhol
2005-06-16 13:10   ` zw
2005-06-15 16:31 ` Georg Bauhaus
2005-06-16  8:18 ` Ole-Hjalmar Kristensen
2005-06-16 11:59   ` Dmitry A. Kazakov [this message]
2005-06-16 13:23     ` zw
2005-06-16 14:19       ` jimmaureenrogers
2005-06-16 14:31       ` Dmitry A. Kazakov
2005-06-19 17:31       ` Martin Krischik
2005-06-19 17:26 ` Martin Krischik
replies disabled

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