comp.lang.ada
 help / color / mirror / Atom feed
* Ada to C Question
@ 2003-04-12 14:43 MPowell
  2003-04-12 14:53 ` Jeffrey Creem
  2003-04-12 19:43 ` tmoran
  0 siblings, 2 replies; 9+ messages in thread
From: MPowell @ 2003-04-12 14:43 UTC (permalink / raw)


Perhaps I'm in the wrong forum but I doing some translation from Ada
to C.
I've noticed in Ada you can do things like.

  type MYTYPE_YOURTYPE      is (MyType,                         -- 0
                                YourType);                       -- 1

  type YOURTYPE_MYTYPE     is (YourType,                       -- 0
                                MyType);                        -- 1




  typedef enum { MyType,
                 YourType } MYTYPE_YOURTYPE ;


Obviously if I typedef on YOURTYPE_MYTYPE the compiler complains so
I'm not sure how to handle this?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Ada to C Question
  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:43 ` tmoran
  1 sibling, 1 reply; 9+ messages in thread
From: Jeffrey Creem @ 2003-04-12 14:53 UTC (permalink / raw)


I suspect you are going to have to add ugly prefixes to all of the members
of the enums.

(e.g
  typedef enum { mtYt_MyType, mtYt_YourType} myTypeYourType;
 )

or something similar.

You will run into similar problems all over the place with overloaded
procedures and even
procedures of the same name in different packages since the C namespace is
global and .h files
are nothing like Ada specs.


There are (commercial/proprietary) tools that can translate from Ada to C.
While they may not do
a perfect job it might be a good starting point.

Even doing a hand translation, you are likely to have some issues since the
code will end up
being structures with an Ada bias which C programmers who work on your code
in the future
will not like.

For instance, it is likely that you may end up with descriptive variable
names and
well structured code.. C programmers hate that :)  (Flames to personal
e-mail only..)

"MPowell" <mpowell_jr@hotmail.com> wrote in message
news:2a159604.0304120643.39f77838@posting.google.com...
> Perhaps I'm in the wrong forum but I doing some translation from Ada
> to C.
> I've noticed in Ada you can do things like.
>
>   type MYTYPE_YOURTYPE      is (MyType,                         -- 0
>                                 YourType);                       -- 1
>
>   type YOURTYPE_MYTYPE     is (YourType,                       -- 0
>                                 MyType);                        -- 1
>
>
>
>
>   typedef enum { MyType,
>                  YourType } MYTYPE_YOURTYPE ;
>
>
> Obviously if I typedef on YOURTYPE_MYTYPE the compiler complains so
> I'm not sure how to handle this?





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Ada to C Question
  2003-04-12 14:53 ` Jeffrey Creem
@ 2003-04-12 17:18   ` MPowell
  2003-04-12 19:16     ` Larry Kilgallen
  0 siblings, 1 reply; 9+ messages in thread
From: MPowell @ 2003-04-12 17:18 UTC (permalink / raw)


> 
> There are (commercial/proprietary) tools that can translate from Ada to C.
> While they may not do
> a perfect job it might be a good starting point.
> 

Jeff any examples per above.  I've seen an Ada2CC utility but not
Ada2C.  I've downloaded a demo copy of the Ada2CC utility but haven't
delved much into it yet.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Ada to C Question
  2003-04-12 17:18   ` MPowell
@ 2003-04-12 19:16     ` Larry Kilgallen
  0 siblings, 0 replies; 9+ messages in thread
From: Larry Kilgallen @ 2003-04-12 19:16 UTC (permalink / raw)


In article <2a159604.0304120918.20fac0d6@posting.google.com>, mpowell_jr@hotmail.com (MPowell) writes:
>> 
>> There are (commercial/proprietary) tools that can translate from Ada to C.
>> While they may not do
>> a perfect job it might be a good starting point.
>> 
> 
> Jeff any examples per above.  I've seen an Ada2CC utility but not
> Ada2C.  I've downloaded a demo copy of the Ada2CC utility but haven't
> delved much into it yet.

	http://www.sofcheck.com/

mentions an AdaMagic front end that generates ANSI C.  For maintainable
ANSI C (as distinguished from repeated conversions), I believe the same
company offers a service.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Ada to C Question
  2003-04-12 14:43 Ada to C Question MPowell
  2003-04-12 14:53 ` Jeffrey Creem
@ 2003-04-12 19:43 ` tmoran
       [not found]   ` <2a159604.0304121850.2820b67f@posting.google.com>
  1 sibling, 1 reply; 9+ messages in thread
From: tmoran @ 2003-04-12 19:43 UTC (permalink / raw)


> I've noticed in Ada you can do things like.
>
>   type MYTYPE_YOURTYPE      is (MyType,                         -- 0
>                                 YourType);                       -- 1
>
>   type YOURTYPE_MYTYPE     is (YourType,                       -- 0
>                                 MyType);                        -- 1
  If the code you are tranlsating has nastiness like that, you better
prepare to redo, rather than just transliterate.  Does the original
program actually work?  Have you found other similar obfuscations yet?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Ada to C Question
       [not found]   ` <2a159604.0304121850.2820b67f@posting.google.com>
@ 2003-04-13  5:37     ` Hyman Rosen
  2003-04-13  6:05     ` tmoran
  1 sibling, 0 replies; 9+ messages in thread
From: Hyman Rosen @ 2003-04-13  5:37 UTC (permalink / raw)


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.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Ada to C Question
       [not found]   ` <2a159604.0304121850.2820b67f@posting.google.com>
  2003-04-13  5:37     ` Hyman Rosen
@ 2003-04-13  6:05     ` tmoran
  2003-04-13 11:34       ` Larry Kilgallen
  2003-04-13 13:38       ` MPowell
  1 sibling, 2 replies; 9+ messages in thread
From: tmoran @ 2003-04-13  6:05 UTC (permalink / raw)


>   type MYTYPE_YOURTYPE      is (MyType,                         -- 0
>                                 YourType);                       -- 1
>
>   type YOURTYPE_MYTYPE     is (YourType,                       -- 0
>                                 MyType);                        -- 1
  Does the program actually care?  Does the representation or the
ordering matter?  Could you perhaps change to
    subtype YOURTYPE_MYTYPE is MYTYPE_YOURTYPE;
with no effect?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Ada to C Question
  2003-04-13  6:05     ` tmoran
@ 2003-04-13 11:34       ` Larry Kilgallen
  2003-04-13 13:38       ` MPowell
  1 sibling, 0 replies; 9+ messages in thread
From: Larry Kilgallen @ 2003-04-13 11:34 UTC (permalink / raw)


In article <377ma.165206$OV.246750@rwcrnsc54>, tmoran@acm.org writes:
>>   type MYTYPE_YOURTYPE      is (MyType,                         -- 0
>>                                 YourType);                       -- 1
>>
>>   type YOURTYPE_MYTYPE     is (YourType,                       -- 0
>>                                 MyType);                        -- 1
>   Does the program actually care?  Does the representation or the
> ordering matter?  Could you perhaps change to
>     subtype YOURTYPE_MYTYPE is MYTYPE_YOURTYPE;
> with no effect?

I would not suggest trial-and-error as a method for determining whether
this matters.   You should review all sites where the enumerated values
are used to check for less-than, greater-than, 'first, 'last and similar
order-dependent constructs.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Ada to C Question
  2003-04-13  6:05     ` tmoran
  2003-04-13 11:34       ` Larry Kilgallen
@ 2003-04-13 13:38       ` MPowell
  1 sibling, 0 replies; 9+ messages in thread
From: MPowell @ 2003-04-13 13:38 UTC (permalink / raw)


tmoran@acm.org wrote in message news:<377ma.165206$OV.246750@rwcrnsc54>...
> >   type MYTYPE_YOURTYPE      is (MyType,                         -- 0
> >                                 YourType);                       -- 1
> >
> >   type YOURTYPE_MYTYPE     is (YourType,                       -- 0
> >                                 MyType);                        -- 1
>   Does the program actually care?  Does the representation or the
> ordering matter?  Could you perhaps change to
>     subtype YOURTYPE_MYTYPE is MYTYPE_YOURTYPE;
> with no effect?

I agree.  In the grand scheme of things I cant imagine/see why the
program woudl care and I'm taking the approach on converting such
that.

Ada
type SubSystem_ID is (A, B);
type System_ID is (A, B, C);

C
typedef enum {A, B, C } System_ID;
No need for 'SubSystem_ID'

If I get a consensus on  C versus ++ then i'll do as one poster
recommended even though it doenst appear feasible to use struct for
what could easily be done with enum.



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-04-13 13:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2003-04-13  6:05     ` tmoran
2003-04-13 11:34       ` Larry Kilgallen
2003-04-13 13:38       ` MPowell

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