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,9e87e366cae15081 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!newscon02.news.prodigy.net!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: if Restrict_Func /= null confusion Date: Sun, 30 Mar 2008 17:37:26 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <95f36a62-b94c-4211-896a-300fa98932b7@x41g2000hsb.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1206913046 4600 192.74.137.71 (30 Mar 2008 21:37:26 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 30 Mar 2008 21:37:26 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:dPPToTus0Kt53kRT98kux1G1Xr0= Xref: g2news1.google.com comp.lang.ada:20655 Date: 2008-03-30T17:37:26-04:00 List-Id: ma740988@gmail.com writes: > Well folks its been at least 4 years since I've perused and/or written > Ada source. That aside I'm perusing source code written in Ada. So > consider: > > -- used to restrict a variable within a range > -- for example: -PI to +PI > type Restrict_Function is access function (X: Real4) return Real4; > > type Filt_Data is > record > Restrict_Func : Restrict_Function ; > > end record ; > > > -- within a procedure we have > Fdata : Filt_Data; > Restrict_Func : Restrict_Function := FData.Restrict_Func ; > > if Restrict_Func /= null then > -- stuff > endif > > At issue: I'm not following the conditional logic 'if (Restrict_Func / > = null)'. Not understanding the impetus behind the check for null. Restrict_Func is a pointer to a function. To call the function, you say something like "Restrict_Func.all(X)". You can leave the ".all" implicit: "Restrict_Func(X)", but the ".all" still happens. ".all" on a null pointer raises an exception. In your example, presumably "stuff" calls the function -- so it needs to be protected by the 'if'. It's usually better to declare: type Restrict_Function is not null access function ...; ^^^^^^^^ so you don't need to worry about null, which is just a tripping hazard. Or use primitive operations of tagged types and dispatching calls. - Bob