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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: How best to test for NULL in Ada? Date: Thu, 02 Jul 2015 16:19:22 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <764f86ed-3b89-4631-b3f3-4d2b1b8d3df0@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Thu, 2 Jul 2015 23:18:00 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="a3855fbfe1a666be9aefba0563039ed5"; logging-data="9467"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gkmHtunqWN+ytd/N3gnoRTVjEyv28kI8=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: <764f86ed-3b89-4631-b3f3-4d2b1b8d3df0@googlegroups.com> Cancel-Lock: sha1:OOUoPp2oMEM8vKyLE2yJPj1XtPs= Xref: news.eternal-september.org comp.lang.ada:26570 Date: 2015-07-02T16:19:22-07:00 List-Id: On 07/02/2015 03:15 PM, NiGHTS wrote: > I have encountered several situations where I needed to test an access type > for NULL or not. My instinct is to do something like this: > > if Some_Object /= null then ... That is correct. > But many times I get this error: > > invalid operand type for operator "/=" left operand has type > "Some_Object_Type" defined at ... right operand has an access type This says that Some_Object is not a value of an access type, so you can't compare it to null. > (If you want a specific example, I am trying to test if the Selected Path > returned by Gtk.Tree_View.Get_Cursor in the GTK Library is valid or NULL. But > situations like these occur many times in distinct situations so I'm not > looking for a fix to this specific problem) The path returned has type Gtk.Tree_Model.Gtk_Tree_Path, which is a tagged record type. Since it's not an access type, you can't compare it to null. You have to compare it to a value of type Gtk.Tree_Model.Gtk_Tree_Path. -- Jeff Carter "What lazy lout left these wires all over the lawn?" Poppy 98