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!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!reality.xs3.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: How best to test for NULL in Ada? Date: Thu, 2 Jul 2015 19:12:51 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <764f86ed-3b89-4631-b3f3-4d2b1b8d3df0@googlegroups.com> NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1435882372 23987 24.196.82.226 (3 Jul 2015 00:12:52 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Fri, 3 Jul 2015 00:12:52 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:26575 Date: 2015-07-02T19:12:51-05:00 List-Id: "Jeffrey R. Carter" wrote in message news:mn4gr7$97r$2@dont-email.me... > 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. Right. You often get an error that the operator is not visible, which means that a suitable "use type" clause is needed. In Ada 2012 there is a hack available to avoid the use clause. (This comes from Tucker Taft, who admitted to doing this during our recent ARG meeting in Madrid. He got suitable groans for this usage...) if Some_Object not in null then This membership uses the predefined equality for the type of Some_Object, and it need not be visible. But this is a hack (it harms readability), and it's dangerous if "=" has been redefined (as it always uses the predefined "=", not the overridden one). Use at your own risk. Randy.