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,e7d9fee9b42cd34e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Fri, 16 Jun 2006 20:15:46 -0500 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: <1150144396.104055.164310@f6g2000cwb.googlegroups.com> Subject: Re: Not null feature with anonymous and named access types Date: Fri, 16 Jun 2006 20:16:33 -0500 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-AtKgluI5z0T8fAWgNerDvviYQw7EeAz0+pP/0yUp5NX2KWPfJboEDQzWUYGcoIONus5Ng2c6S/4Cn49!18wLQBBEA1IhaoQpr20MG++z0djUxxMmNyyb/b/bYVQOFxkPQZDvt5tbPjCB8pTG8FqlraYqRMKV!PpIKBHOkizDyUg== 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:4800 Date: 2006-06-16T20:16:33-05:00 List-Id: "Anh Vo" wrote in message news:1150144396.104055.164310@f6g2000cwb.googlegroups.com... > I have been exploring the not null feature with anonymous access type > and named access type. One thing have learned that an access variable > declared based on these types will raise a Constraint_Error when > deallocating this access variable as shown in the code below. > > Access_Type: > declare > type Access_Integer is not null access all Integer; It's virtually always wrong to declare a *type* with "not null". It's use should primarily be restricted to subtypes and parameters. > procedure Free is new Unchecked_Deallocation (Integer, > Access_Integer); This instantiation is illegal; the "not null" property must match between the formal and actual types. See 12.5.4(4/2). > My_Ref_1 : Access_Integer := new Integer' (111); > My_Ref_2 : not null access Integer := new Integer' (222); > begin > -- perform action on My_Ref_1 and My_Ref_2 > Free (My_Ref_1); -- raising Constraint_Error under GNAT/gcc-4.2.0 You shouldn't have been able to run this program. > Free (Access_Integer (My_Ref_2)); -- did too > end Access_Type; > > Does this behavior reflect ARM 2005 requirements? No, see above. > Thanks in advance for your comments. As I said above, never declare a null-excluding type; it's impossible to use in any meaningful way. Use "not null" in subtypes, object declarations, parameters, and the like. (Parameters are expected to be the primary use.) I'd write your example like: Access_Type: declare type Access_Integer is access all Integer; procedure Free is new Unchecked_Deallocation (Integer, Access_Integer); My_Ref_1 : Access_Integer := new Integer' (111); My_Ref_2 : not null access Integer := new Integer' (222); begin -- perform action on My_Ref_1 and My_Ref_2 Free (My_Ref_1); -- OK. --Free (Access_Integer (My_Ref_2)); -- Raises Constraint_Error. My_Ref_1 := My_Ref_2; Free (My_Ref_1); -- OK. end Access_Type; (But the important use of "not null" is in passing parameters.) Randy.