comp.lang.ada
 help / color / mirror / Atom feed
From: Hyman Rosen <hyrosen@mail.com>
Subject: Re: Ada to C Question
Date: Sun, 13 Apr 2003 05:37:50 GMT
Date: 2003-04-13T05:37:50+00:00	[thread overview]
Message-ID: <OI6ma.8317$Gb1.205@nwrdny01.gnilink.net> (raw)
In-Reply-To: <2a159604.0304121850.2820b67f@posting.google.com>

MPowell wrote:
> Of course in C (porting to C) declarations above don't work.  As far
> as the typedef sees 'it' some parameters are just re-declarations.

The right way to do these in C++ is as follows:
     struct SET_RESET_TYPE { enum { Set, Reset } e; };
     struct RESET_SET_TYPE { enum { Reset, Set } e; };
     // etc.
and qualify the literals with the appropriate type, eg.,
     SET_RESET_TYPE::Set

> I'm not sure how I could handle 'generics' in C.  So now:
> 
> generic
>  type ELEMENT is private;
>  Initial_Element : ELEMENT;
> 
> package Protected_Msg is 
>   function Read return ELEMENT;
>   procedure Push (E : Element);
> end Protected_Msg;
> 
> the package body follows.

Again, use C++. Things may vary depending on how Initial_Element is used.
     template <typename ELEMENT>
     struct Protected_Msg {
         static ELEMENT Read();
         static void Push(ELEMENT);
         static ELEMENT Initial_Element();
     };

> type TEMPERATURE is Float;
> subtype TEMP_RANGE is TEMPERATURE range -50 .. 50;
> 
> I like subtypes in Ada but no way to handle subtypes in C so I have to
> use #define max and min and use if statments.

Again, using C++ you could define a class which would do the range checks.




  parent reply	other threads:[~2003-04-13  5:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-12 14:43 Ada to C Question MPowell
2003-04-12 14:53 ` Jeffrey Creem
2003-04-12 17:18   ` MPowell
2003-04-12 19:16     ` Larry Kilgallen
2003-04-12 19:43 ` tmoran
     [not found]   ` <2a159604.0304121850.2820b67f@posting.google.com>
2003-04-13  5:37     ` Hyman Rosen [this message]
2003-04-13  6:05     ` tmoran
2003-04-13 11:34       ` Larry Kilgallen
2003-04-13 13:38       ` MPowell
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox