C99 to C89 translator

Discussion in 'C Programming' started by napi, Jun 3, 2005.

  1. napi

    napi Guest

    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
     
    napi, Jun 3, 2005
    #1
    1. Advertisements

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


    <<Remove the del for email>>
     
    Barry Schwarz, Jun 3, 2005
    #2
    1. Advertisements

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

    http://www.comeaucomputing.com/
     
    E. Robert Tisdale, Jun 3, 2005
    #3
  4. napi

    Jack Klein Guest

    I think Greg Commeau's product can do it.

    http://www.comeaucomputing.com
     
    Jack Klein, Jun 3, 2005
    #4
  5. Hello,

    Use malloc() and free() instead?

    Regards,
    Spiro.
     
    Spiro Trikaliotis, Jun 3, 2005
    #5
  6. napi

    Philip Paeps Guest

    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
    I follow the newsgroup.

    If you plan to leave your mark in the sands of time,
    you better wear work shoes.
     
    Philip Paeps, Jun 3, 2005
    #6
  7. 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.
     
    Keith Thompson, Jun 3, 2005
    #7
  8. 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>>
     
    Barry Schwarz, Jun 4, 2005
    #8
  9. 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>>
     
    Barry Schwarz, Jun 4, 2005
    #9
  10. 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).
     
    E. Robert Tisdale, Jun 4, 2005
    #10
  11. napi

    Greg Comeau Guest

    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 :)
     
    Greg Comeau, Jun 5, 2005
    #11
  12. napi

    Greg Comeau Guest

    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).
     
    Greg Comeau, Jun 5, 2005
    #12
  13. napi

    Greg Comeau Guest

    Yes, but a C99 translator can also be one of them.
    If he really needs C99 he doesn't need to consider that,
    unless some other considerations point in that direction.
    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.
     
    Greg Comeau, Jun 5, 2005
    #13
  14. napi

    Greg Comeau Guest

    Right, which need not be a requirement in all cases if it can be
    provided proper support.
    Besides that it is probably not possible (tgmath, VLAs, complex, etc
    come to mind), on the parts that are that would be interesting indeed.
    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.
     
    Greg Comeau, Jun 5, 2005
    #14
  15. napi

    Greg Comeau Guest

    Hopefully it is between C99 and C99! :)
     
    Greg Comeau, Jun 5, 2005
    #15
  16. napi

    CBFalconer Guest

    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.
     
    CBFalconer, Jun 5, 2005
    #16
  17. napi

    CBFalconer Guest

    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.
     
    CBFalconer, Jun 5, 2005
    #17
  18. napi

    Ben Pfaff Guest

    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.
     
    Ben Pfaff, Jun 6, 2005
    #18
  19. napi

    CBFalconer Guest

    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. :)
     
    CBFalconer, Jun 6, 2005
    #19
  20. napi

    Randy Howard Guest

    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?
     
    Randy Howard, Jun 6, 2005
    #20
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.