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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8f7d6c5172a1d41b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Wed, 24 Jan 2007 14:50:43 -0600 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: <3vwf1b4b2ntl$.l9n17zmh9v8a$.dlg@40tude.net> <1u2mhr9ypij4u.bn3yayn7o9l3$.dlg@40tude.net> Subject: Re: [Revisited] How to get around "access type must not be outside generic unit" Date: Wed, 24 Jan 2007 14:50:49 -0600 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 Message-ID: NNTP-Posting-Host: 64.32.209.38 X-Trace: sv3-Uatn6MkeKU5WORgyxBlpihBk+SIQ508aDWSiP5/xFvgG2MAqQL3bBNAgUHtxmuoZWfaTqhoekD0i0+9!FABtAC4+dD6k/a8Rb5xBKLRxqejlXeGG+temCepCqLPBJaTYCiDluJghqqkfhxSXbNMlm0Ubvoor!J5RL0fPVZCKCAA== X-Complaints-To: abuse@megapath.net X-DMCA-Complaints-To: abuse@megapath.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news2.google.com comp.lang.ada:8513 Date: 2007-01-24T14:50:49-06:00 List-Id: "Dmitry A. Kazakov" wrote in message news:1u2mhr9ypij4u.bn3yayn7o9l3$.dlg@40tude.net... ... > > That won't work in a compiler that does generic code sharing (like > > Janus/Ada). Subprograms in a generic have an extra hidden parameter to carry > > the instance descriptor, and thus the profile doesn't match that of a > > routine outside of a generic. There is absoletely no way to change this > > inside of the generic body short of completely abandoning the code sharing > > model. > > And what Janus/Ada would do if it meets pragma Convention (C, Foo); ? I'm not sure. Doesn't matter anyway, because you can't do anything with such a routine (as you are finding out). 'Access ensures that the profile is "correct"; it's got nothing to do with the Convention pragma on the subprogram. ... > > But in any case, the solution to your problem (as always) is to put the > > 'Access into the private part of the specification. Do that with an > > appropriate constant declaration. (If the parameter type of Register was > > anonymous, there is no problem, so there must be a named type that can be > > used.) Doing so will force the generic to be instantiated at the library > > level. > > OK, that's definitely better than Unchecked_Conversion. In Ada 95 it was > enough to add a declaration of the subprogram to the specification, now we > also need an access object. This is strange, at least not obvious. Why > should it change anything? Because it's part of the contract model. That is assume-the-best in the visible part of the spec, and assume-the-worst in the body. (We're somewhat confused about the private part.) Whenever we assume-the-best, there is a required recheck in the instance. Thus, putting such a 'Access in the spec means that it will be rechecked and rejected if it causes trouble. In this case, that means that the generic will be rejected if it is instantiated in a nested scope. > I mean, if it is semantically correct, then why > the compiler cannot deduce it? Is it semantically correct? In the case with > Glib above, would it be possible to instantiate a generic package in a > local scope; call to Boxed_Type_Register_Static passing a constant as you > described; and then leave the scope? No, the instance will be rejected at compile-time as failing an accessibility check. In terms of the shared implementation, what happens is that the instance makes a wrapper for the routine with the "correct" profile for 'access. You can't do that in the body when sharing, because you always need the instance descriptor parameter there. In spec, you can do it both ways to allow calling from both the internal and external views. That's because you know where the instance descriptor is for the particular instance, and can include it in the wrapper call. Randy.