comp.lang.ada
 help / color / mirror / Atom feed
From: "SteveD" <nospam_steved94@attbi.com>
Subject: Re: Commercial C To Ada 95 compiler
Date: Sat, 08 Jun 2002 04:46:18 GMT
Date: 2002-06-08T04:46:18+00:00	[thread overview]
Message-ID: <u_fM8.215645$Po6.363686@rwcrnsc52.ops.asp.att.net> (raw)
In-Reply-To: 3D018106.6080004@worldnet.att.net

"Jim Rogers" <jimmaureenrogers@worldnet.att.net> wrote in message
news:3D018106.6080004@worldnet.att.net...
> SteveD wrote:
>
[snip]
>
> You may be very wrong here. Ada compilers tend to identify many more
> errors at compile time than C compilers. This means that code
> which compiles without error on a C compiler, when directly translated
> to Ada, will may not compile.
>
> One simple example is indexing past the end of an array.
> C compilers simply will not catch this problem. Ada compilers will.

In fact this is not an error in C.  Programs can (and do) intentionally
index past the end of arrays.  I have seen C code that allocates memory
dynamically and uses array access to reference the memory.  It is nearly
impossible to distinguish these cases.

> On the whole, direct translation may not be possible. C uses
> implicit conversion between integer and floating point types.
> Ada provides no such implicit conversion. You will at least need
> to make all implicit C conversions explicit in Ada.

I disagree, direct translation is possible.  The order of conversions in C
is explicitly defined.  The translation would have to turn these implicit
conversions into explicit conversions.  Again, a review of the translated
could may reveal surprises.

> Another incompatibility is trying to reference the control
> variable in a "for" loop outside the scope of the "for" loop.
> This is impossible in Ada and not uncommon in C. The C compiler
> will allow this. The Ada compiler will not.

In this case a direct translation should translate the for loop to a while
construct.  For a direct translation the generated code must behave exactly
the same as the original code.

> Your example of "direct" translation of a C for loop with a null
> body to an Ada while loop is a good approximation of the problem,
> but not, IMHO, a direct translation. A direct translation would have
> the C code also using a while loop. Ada for loops simply cannot
> demonstrate this error. Any attempt to do so will create a
> compiler error.

You miss my point.  The translation is from C to Ada.  I can't change the C
code, I'm translating it.

In my example the C code had an error, the fact that the for loop was empty
was missed in the original code.  This shows up readily in the Ada code.

BTW:  I'm not saying I would want a C to Ada translator.  I'm just saying
that if someone said they wanted one, I can understand their reasoning.

SteveD

>
> Jim Rogers
>





  parent reply	other threads:[~2002-06-08  4:46 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-03  9:26 Commercial C To Ada 95 compiler Henrik Quintel
2002-06-03 18:52 ` Ingo Marks
2002-06-04  6:40   ` Henrik Quintel
2002-06-04 14:11     ` Frank J. Lhota
2002-06-04 14:26       ` Preben Randhol
2002-06-04 16:38         ` Frank J. Lhota
2002-06-03 20:26 ` Florian Weimer
2002-06-04  6:43   ` Henrik Quintel
2002-06-04 14:18     ` Lutz Donnerhacke
2002-06-07  3:48 ` Richard Riehle
2002-06-07 12:46   ` SteveD
2002-06-07 13:20     ` Marin David Condic
2002-06-09 21:43       ` Stephen Leake
2002-06-10 13:17         ` Marin David Condic
2002-06-11 12:52           ` SteveD
2002-06-11 13:32             ` Marin David Condic
2002-06-12 14:07               ` Larry Kilgallen
2002-06-12 13:21                 ` Marin David Condic
2002-06-07 13:21   ` Larry Kilgallen
2002-06-07 19:48     ` Ted Dennison
2002-06-07 20:26       ` Wes Groleau
2002-06-08  3:19         ` SteveD
2002-06-08  3:59           ` Jim Rogers
2002-06-08  4:14             ` Darren New
2002-06-08  4:50               ` SteveD
2002-06-08 12:04                 ` Robert Dewar
2002-06-10 18:44               ` Wes Groleau
2002-06-10 19:23                 ` Darren New
2002-06-10 20:55                   ` Wes Groleau
2002-06-10 21:03                     ` Darren New
2002-06-08  4:46             ` SteveD [this message]
2002-06-08 12:11               ` Robert Dewar
2002-06-08 18:46                 ` SteveD
2002-06-10 13:34                   ` Marin David Condic
2002-06-11 16:38                     ` Wes Groleau
2002-06-11 17:27                       ` Marin David Condic
2002-06-12 13:18                         ` Pascal Obry
2002-06-10 18:47               ` Wes Groleau
2002-06-10 21:23                 ` Larry Kilgallen
2002-06-10 20:59                   ` Wes Groleau
2002-06-10 21:37                     ` Robert A Duff
2002-06-10 22:34                       ` Wes Groleau
2002-06-08 12:06             ` Robert Dewar
2002-06-08 15:53             ` Richard Riehle
2002-06-08 15:58               ` Preben Randhol
2002-06-10 13:37                 ` Marin David Condic
2002-06-10 23:32                   ` Darren New
2002-06-11 13:11                     ` Marin David Condic
2002-06-12 15:42                       ` Darren New
2002-06-21 17:23                         ` David Thompson
2002-06-08 17:45               ` tmoran
2002-06-08 18:32               ` Pascal Obry
2002-06-09 17:41                 ` Richard Riehle
2002-06-10  8:11                   ` Fraser Wilson
2002-06-08 20:06               ` Jim Rogers
2002-06-09 17:49                 ` Richard Riehle
replies disabled

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