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,FREEMAIL_FROM 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!news3.google.com!news.glorb.com!aioe.org!not-for-mail From: Cesar Rabak Newsgroups: comp.lang.ada Subject: Re: Translating an embedded C algorithm Date: Thu, 18 Jan 2007 21:34:40 -0200 Organization: Aioe.org NNTP Server Message-ID: References: <1168871816.263502.212100@11g2000cwr.googlegroups.com> <45acc0c3$0$22514$39db0f71@news.song.fi> <45af9c60$0$22524$39db0f71@news.song.fi> NNTP-Posting-Host: zEJK12x7djBBvRARhduGQA.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org In-Reply-To: User-Agent: Thunderbird 1.5.0.8 (X11/20061109) Xref: g2news2.google.com comp.lang.ada:8291 Date: 2007-01-18T21:34:40-02:00 List-Id: Niklas Holsti escreveu: > Niklas Holsti wrote: >> ... >> >> I agree with other posters that simply translating this function into >> Ada does not give a good comparison between C and Ada. The first steps >> in an Ada design would be to consider encapsulation (packages) and >> data representation (types), for which the C version gives no model. > > I'm replying to my own post because I've changed my opinion a bit: I > think that an Ada translation of this C function can, with a bit of > elaboration, illustrate several Ada features for "programming in the > small", even if not for "programming in the large". > > So here is my try at an Ada version of the code and some of the context. > This makes for a long post, for which I apologize in advance. Putting > the sources somewhere for download seemed like overkill, and I prefer to > expose my suggestion to the purifying flames of c.l.a instead of sending > it privately to the OP. The Ada code below has been compiled > and tested (gnat 3.15p, Debian). It is hereby put in the public domain. Nice! I will only make a pair of comments that I believe relate to the OP idea, and will skip suggestions or observations which in the bottom line may be considered by other engineers as stylistic. > > In this code, I tried to use as many relevant Ada features as possible, > without trying to limit myself to some "8-bit subset". It would be > interesting to compile this code with AVR-Ada; I don't happen to have > that installed, but I may try it later, if no-one else does it. Note that the home page for AVR-Ada has this (Status 2nd paragraph): "The Ada run time system (RTS) on the other hand is for the most part not even a run time system. It is more a compile time system :-). Most files in the RTS are only needed at compile time. As a consequence we don't yet have support for exceptions nor for tasking (multi-threading)." [snipped] > and > > package Temperatures is > > type Celsius_T is delta 0.1 digits 5 range -40.0 .. 120.0; > -- > -- A temperature in degrees Celsius. > > -- More temperature stuff ... > > end Temperatures; I don't know how an Ada compiler targeted for microcontrollers would make the internal representation of this type, but if it employs more than a 16 bit word, I would rather stick to the other implementation elsethread. [snipped] HTH -- Cesar Rabak