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,f822ae7b0f7433c1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!208.49.83.154.MISMATCH!uns-out.usenetserver.com!news.usenetserver.com!pc03.usenetserver.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail Newsgroups: comp.lang.ada Subject: Re: AW: Translating an embedded C algorithm References: <878xg2aqzr.fsf@ludovic-brenta.org> <87k5zk7m8j.fsf@ludovic-brenta.org> From: Stephen Leake Date: Fri, 19 Jan 2007 04:33:42 -0500 Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (windows-nt) Cancel-Lock: sha1:J0JQsRyMkrQILE7EVmRw0DXvlCE= MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: 1624f45b09078759e00d424878 Xref: g2news2.google.com comp.lang.ada:8317 Date: 2007-01-19T04:33:42-05:00 List-Id: Ludovic Brenta writes: > Markus E Leypold writes: >> Ludovic Brenta writes: >>> Right, and there would be no need for a silly INVALID_TEMPERATURE. >>> What *is* an invalid temperature anyway? One that needs crutches? >>> One that is excused from military service? And why would you ever >>> return an invalid temperature to your caller? etc. etc. >> >> | >> --| Temperature in �C x 10. INVALID_TEMPERATURE if out of range. >> >> If the sensor is out of order or the temperature leaves the range >> where it functions properly? >> >> :-). > > My point it this: if the sensor is out of order, then there is no > known temperature; not a known "invalid" temperature. The proper way > to handle that in Ada is with an exception, not a special value of > type Degrees_C. In a real-time system that is tolerant of hardware failures, every hardware measurement should be accompanied by some sort of quality flag. In this case, a boolean would do; Temperature_Valid. The point is that when hardware failures are expected, they are best handled by normal data, not exceptions. Using a special value of Temperature to represent hardware failure is an example of in-band signaling; using a separate quality flag is out-of-band signaling. Out-of-band is a bit more complicated, but much more robust. This example program is far too small to show the crucial differences between C and Ada. -- -- Stephe