Re: Certified C compilers for safety-critical embedded systems

From: CBFalconer (cbfalconer_at_yahoo.com)
Date: 12/30/03


Date: Tue, 30 Dec 2003 21:15:46 GMT

Dave Hansen wrote:
>
... snip ...
>
> Many consider the terseness of C to be a problem or even a
> disadvantage. But sometimes it helps in comprehension. Consider:
>
> int key;
> extern int get_key(void);
> extern void process(int);
> #define EXIT_KEY 'X'
>
> while ( (key = get_key()) != EXIT_KEY )
> process(key);
>
> How do you do that in Ada?

I won't answer that, but here is how I would do it in Pascal:

   FUNCTION nextkey(VAR keyval : char) : boolean;

      BEGIN
      keyval = get_key;
      nextkey = keyval <> EXIT_KEY;
      END;

   BEGIN
   ....
   WHILE nextkey(key) DO process(key);
   ....

I have no qualms about factoring out baby subroutines.

-- 
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!


Relevant Pages