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,1e36228aae0595da X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.k-dsl.de!news.motzarella.org!motzarella.org!not-for-mail From: =?ISO-8859-2?Q?Pawe=B3_=27Nivertius=27_P=B3azie=F1ski?= Newsgroups: comp.lang.ada Subject: Re: Access to function returning class-wide type Date: Thu, 21 Aug 2008 21:22:29 +0200 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 8Bit X-Trace: feeder.motzarella.org U2FsdGVkX18Gz3bZ9iZayKXSUr2pYQ6CXDKqMpQqUlmMq0qwl9NLAqsBENFN1QMzxNERu5bcMeQtCJ3QTyjH3VHnnLcU+fNPnzlHmMegSAqjlWpZAcYSB2SP1xDhEFQyLf54zoizntzBE6ogUlrOcA== X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers NNTP-Posting-Date: Thu, 21 Aug 2008 19:27:06 +0000 (UTC) X-Auth-Sender: U2FsdGVkX18wYd0w018wpENCapXENRX2HTK/hdSzk2EyEr+AZ0n8Tw== Cancel-Lock: sha1:vS5Ns3SM/yMkErpNXa1/O23HOzE= User-Agent: KNode/0.10.9 Xref: g2news1.google.com comp.lang.ada:1737 Date: 2008-08-21T21:22:29+02:00 List-Id: Adam Beneschan wrote: > Others have posted discussions of how to accomplish what you want, or > what we think you might want, using a different construct. I watched comp.lang.ada for little time, searched through posts which I got and I belive I didn't see that. I'm sorry if I browsed to short. > I just wanted to point out that, from a low-level standpoint, there's > no way to have an access type that could refer to *both* a function > that returns Abstracted'Class *and* a function that returns the > specific type Derived. The reason is that an access-to-function is > basically just going to hold the address of the function (and some > other information). A function that returns T'Class can't work the > same as a function that returns a specific type, because the function > that returns T'Class won't know in advance how big the return object > is going to be, so some dynamic heap (or "secondary stack") allocation > must be involved. A function that returns Derived, though, knows how > big the return object is, so the result can be pre-allocated. This > means that both the function and the function's caller have to adopt > different mechanisms for passing the return object between them. If > you have an access-to-function which could point to either one, the > code that makes a call through this access-to-function pointer isn't > going to know which return object mechanism would be used, so the > result would be a mess. > > If Ada were to provide a mechanism so that B.Proc'Access could be > used, the compiler would have to generate its own wrapper, same as > you're doing. This isn't necessarily a bad thing; there are already > other cases where Ada compilers have to generate wrappers (at least > ours does). But I think it's useful to understand the underlying > mechanisms involved, to get a better understanding of why the language > won't let you do certain things. I think I understand what you want to show me. As I posted in other thread [see news:g8jf3n$e00$1@registered.motzarella.org ], I've made a test with type/subtype and it's failing as well. There is a more obvious collision there, we expect a function which doesn't do dynamic range check on returned object, and we pass a function which does. > By the way, if you decide that the other suggestions don't work and > you need to write a wrapper anyway, you shouldn't have to rewrite the > whole wrapper for every type; I think you can use a generic to make > the process of declaring the wrapper a lot simpler. As I've shown in original post, the wrapper needs to consist only a return statement from 'main' constructor. I'll try to do it with generic function as you suggest, but in the worst case the difference will be... well... small ;-) -- Pawe� P�azie�ski aka Nivertius "In the end, there will be Ada, XML and gzip"