C99 to C89 translator

N

napi

Does anybody know if there's any C99 to C89 translator out there,
either free
or commercial. I searched on Google but couldn't see it so far.
Thanks for any tips.

Napi
 
B

Barry Schwarz

Does anybody know if there's any C99 to C89 translator out there,
either free
or commercial. I searched on Google but couldn't see it so far.
Thanks for any tips.

And what would you expect a translator to do with a variable length
array?


<<Remove the del for email>>
 
S

Spiro Trikaliotis

Hello,

Barry Schwarz said:
And what would you expect a translator to do with a variable length
array?

Use malloc() and free() instead?

Regards,
Spiro.
 
P

Philip Paeps

napi said:
Does anybody know if there's any C99 to C89 translator out there, either
free or commercial. I searched on Google but couldn't see it so far.
Thanks for any tips.

Isn't it easier to either a) just use a C99 compiler or b) restrict yourself
to writing C89 code? It's my experience that this sort of translators often
cause more problems than they fix. The best 'translator' is still a human
being who knows what the code is supposed to do...

- Philip

--
Philip Paeps Please don't email any replies
(e-mail address removed) I follow the newsgroup.

If you plan to leave your mark in the sands of time,
you better wear work shoes.
 
K

Keith Thompson

napi said:
Does anybody know if there's any C99 to C89 translator out there,
either free or commercial. I searched on Google but couldn't see it
so far. Thanks for any tips.

I suspect the most likely way to implement a C99 to C89 "translator"
would be as a C99 compiler that produces C89 as its intermediate
language. The resulting C89 code is not likely to be legible or
maintainable.

On the other hand, a translator that generates *legible* C89 code (and
that makes few or no changes to C99 code that happens to be legal C89
code with the same semantics) might be an interesting thing. It
*might* even be useful.

VLAs could be translated to malloc() calls (and code to crash the
program if malloc() returns NULL). Calls type-generic math functions
could be translated to direct calls to the appropriate function for
the type. The "restrict" keyword could just be ignored. Type long
long would have to be implemented with library calls (or as type long
if long happens to be big enough).

If you insist on translating strictly conforming C99 to strictly
conforming C89, the translation limits are going to be a problem (for
example, 63 rather than rather than 32 levels of nested parentheses in
an expression). Realistically, though, most C89 compilers don't
impose fixed limits on that kind of thing.

And so on.
 
B

Barry Schwarz

I don't know.
What does the Comeau C99 compiler do with variable length arrays?

Is the C99 compiler a translator between C99 and C89? No, it is a
translator between C99 and machine code.

Why did you extract the sentence out of context? Do you have
something to contribute to the original question?


<<Remove the del for email>>
 
B

Barry Schwarz

Hello,



Use malloc() and free() instead?

Which would require the use of a synthetic pointer. But what happens
when the array is the operand of sizeof and & operators? And the new
"type" pointer to variable length array is handled how?


<<Remove the del for email>>
 
E

E. Robert Tisdale

Barry said:
Is the C99 compiler a translator between C99 and C89?

Yes.
See

http://www.comeaucomputing.com/

What Is Comeau C/C++ 4.3.3?

Comeau C/C++ is a command line driven C and C++ compiler that generates
platform specific and C compiler specific C as its object code (the
generated C code won't work on another platform, as it is CPU, OS and C
compiler specific, and furthermore, it is not standalone). It then
transparently invokes a particular C compiler that we've specifically
ported it to (again, it won't work with one we haven't ported it to --
such porting must be done by Comeau since particulars must be coded into
the compiler and library itself).
 
G

Greg Comeau

And what would you expect a translator to do with a variable length
array?

Translate it.

There is perhaps 2 questions on the table here.
One is to translate it to a new source code form.
That is probably not possible.

The other is translatation with runtime library support of
the translator/translated code, hence the RTL and the
generated code conspiring to achieve the desired result.

Neither would probably be readable :)
 
G

Greg Comeau

I don't know.
What does the Comeau C99 compiler do with variable length arrays?

Current versions make use of our own routines that allow them
to be declared, and for operations to be performed on them.

We can also re-emit them as VLAs if for some reason the backend
has optimized them in some special way(s).
 
G

Greg Comeau

Isn't it easier to either a) just use a C99 compiler

Yes, but a C99 translator can also be one of them.
or b) restrict yourself
to writing C89 code?

If he really needs C99 he doesn't need to consider that,
unless some other considerations point in that direction.
It's my experience that this sort of translators often
cause more problems than they fix. The best 'translator' is still a human
being who knows what the code is supposed to do...

This is a bit confusing statement. For instance, if that's so,
why do you program in C?

Also, indeed there are many poor translators out there,
just like there are many good ones, and just like there are
many poor compilers, as afterall, a compiler is a particular
type of translator.
 
G

Greg Comeau

I suspect the most likely way to implement a C99 to C89 "translator"
would be as a C99 compiler that produces C89 as its intermediate
language. The resulting C89 code is not likely to be legible or
maintainable.

Right, which need not be a requirement in all cases if it can be
provided proper support.
On the other hand, a translator that generates *legible* C89 code (and
that makes few or no changes to C99 code that happens to be legal C89
code with the same semantics) might be an interesting thing. It
*might* even be useful.

Besides that it is probably not possible (tgmath, VLAs, complex, etc
come to mind), on the parts that are that would be interesting indeed.
VLAs could be translated to malloc() calls (and code to crash the
program if malloc() returns NULL). Calls type-generic math functions
could be translated to direct calls to the appropriate function for
the type. The "restrict" keyword could just be ignored. Type long
long would have to be implemented with library calls (or as type long
if long happens to be big enough).

My above comment was not to negate your above, but in enough
case I suspect that the function calls might be overbearing
districting the readability. Just guessing though.
 
C

CBFalconer

E. Robert Tisdale said:
Yes.
See

http://www.comeaucomputing.com/

What Is Comeau C/C++ 4.3.3?

Comeau C/C++ is a command line driven C and C++ compiler that
generates platform specific and C compiler specific C as its
object code (the generated C code won't work on another platform,
as it is CPU, OS and C compiler specific, and furthermore, it is
not standalone). It then transparently invokes a particular C
compiler that we've specifically ported it to (again, it won't
work with one we haven't ported it to -- such porting must be
done by Comeau since particulars must be coded into the compiler
and library itself).

WARNING - our resident Trollsdale is now trying to give the
impression he has something to do with Comeau. AFAIK he does not,
and will not. Comeau is respectable.
 
C

CBFalconer

Greg said:
Translate it.

There is perhaps 2 questions on the table here. One is to translate
it to a new source code form. That is probably not possible.

The other is translatation with runtime library support of the
translator/translated code, hence the RTL and the generated code
conspiring to achieve the desired result.

Neither would probably be readable :)

As long as you can customize to the non-standard aspects of a
particular compiler, you probably have many possibilities. One is
alloca. Another is to simply malloc and free on function exit.
The point is that it doesn't matter, except to the implementor.
The user has a standard approved means of expressing himself.
 
B

Ben Pfaff

CBFalconer said:
As long as you can customize to the non-standard aspects of a
particular compiler, you probably have many possibilities. One is
alloca.

The GCC manual notes that VLAs and alloca have different
semantics:

You can use the function `alloca' to get an effect much like
variable-length arrays. The function `alloca' is available in many
other C implementations (but not in all). On the other hand,
variable-length arrays are more elegant.

There are other differences between these two methods. Space
allocated with `alloca' exists until the containing _function_ returns.
The space for a variable-length array is deallocated as soon as the
array name's scope ends.
 
C

CBFalconer

Ben said:
[As a suggestion for translating VLAs into C89]
As long as you can customize to the non-standard aspects of a
particular compiler, you probably have many possibilities. One
is alloca.

The GCC manual notes that VLAs and alloca have different
semantics:

You snipped too much, in particular the following sentence:

"The point is that it doesn't matter, except to the implementor.
The user has a standard approved means of expressing himself."

After all, "mov r1, r2" also has different semantics. :)
 
R

Randy Howard

WARNING - our resident Trollsdale is now trying to give the
impression he has something to do with Comeau. AFAIK he does not,
and will not. Comeau is respectable.

I see nothing above to indicate ERT is trying to claim he has anything
to do with it. On what do you base this claim?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top