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-7-bit Path: g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!fi.sn.net!newsfeed2.fi.sn.net!news.song.fi!not-for-mail Date: Thu, 18 Jan 2007 22:19:14 +0200 From: Niklas Holsti User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20060628 Debian/1.7.8-1sarge7.1 X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Translating an embedded C algorithm References: <1168871816.263502.212100@11g2000cwr.googlegroups.com> <45acc0c3$0$22514$39db0f71@news.song.fi> <45af9c60$0$22524$39db0f71@news.song.fi> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <45afd503$0$22528$39db0f71@news.song.fi> Organization: TDC Song Internet Services NNTP-Posting-Host: laku61.adsl.netsonic.fi X-Trace: 1169151235 news.song.fi 22528 81.17.205.61:32893 X-Complaints-To: abuse@song.fi Xref: g2news2.google.com comp.lang.ada:8279 Date: 2007-01-18T22:19:14+02:00 List-Id: Jeffrey Carter wrote: > Niklas Holsti wrote: > >> package ADC is >> >> type Count_T is range 0 .. 1023; > > > Why not mod 2 ** 10? Yes, that would be possible. But the code did not need logical bit-wise operations nor shifting (because, following the OP, I assumed that the compiler is smart enough to use shifting for divisions and remainders where the right operand is a power of 2). Modular arithmetic for ADC readings also seems undesirable; if it overflows I don't want wrap-around, I want Constraint_Error (or saturation, but Ada has no predefined forms of saturating integer types). > Is > > for Count_T'Size use 10; > > appropriate here? I don't see any reason for it in this example. If we had some packed data structures with Count_T components, sure. > Seems to me these are only used to produce temperatures, and so should > be hidden from the rest of the application. As I replied to Ludovic, I assumed that the same ADC is used to measure other sensors, too. The question of the public visibility of ADC.Count_T is a question of "programming in the large", for example which part of the SW is actually reading the ADC, and whether we can encapsulate all ADC interactions under the hierarchy of package ADC, in which case the type Count_T could be hidden in this hierarchy, as you suggest. >> Saturation : Boolean := True; > > > Control coupling through global variables. Terrible SW engineering. What > happens when one task changes the value when another is part way through > the function? I considered the alternative of making Saturation a parameter with a default value: function Temperature ( Count : Count; Saturation : Boolean := True) return Reading_T; but I wanted to demonstrate mutable package state in the simplest possible way. I agree that "in the large" such freely mutable variables are usually a bad idea, and especially in multi-threaded programs, as you say. If we want to follow the original C code exactly then the saturation option should of course be removed (assumed always true). -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .