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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,32cfbb718858528b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-08 05:11:38 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: dewar@gnat.com (Robert Dewar) Newsgroups: comp.lang.ada Subject: Re: Commercial C To Ada 95 compiler Date: 8 Jun 2002 05:11:38 -0700 Organization: http://groups.google.com/ Message-ID: <5ee5b646.0206080411.7da58d12@posting.google.com> References: <3D002D11.CC706952@adaworks.com> <4519e058.0206071148.9b87acf@posting.google.com> <3D0116F3.7254E263@despammed.com> <3D018106.6080004@worldnet.att.net> NNTP-Posting-Host: 205.232.38.247 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1023538298 12372 127.0.0.1 (8 Jun 2002 12:11:38 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 8 Jun 2002 12:11:38 GMT Xref: archiver1.google.com comp.lang.ada:25522 Date: 2002-06-08T12:11:38+00:00 List-Id: > 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. This is an erroneous C program. Definitely it will be hard to translate programs that are erroneous and have undefined semantics. Or from a more formal point of view, ANY translation of such a program is correct! Many C programmers think C has general address arithmetic. It does not. If you want general address arithmetic, you must use some other language, e.g. Ada, which does have this feature. > > 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. A better response is that there is no "for" loop in C. The thing that looks like a for loop in C is (and is defined to be) simply a macro form for a while loop. Most obviously it must be translated into a while loop. In general the point is that a translator that does this kind of translation must have all the intelligence and semantic knowledge of a C compiler (and must be written by someone who knows the formal semantics and typical usage of both languages comprehensively).