K&R -> C99?

Discussion in 'C Programming' started by Zach, Aug 4, 2007.

  1. Zach

    Zach Guest

    Looking for a program that will convert K&R C source files (including
    headers) to C99 (or at least some early ANSI standard) and it must
    recognize typedefs and preserve argument promotion; protoize doesn't
    and cproto tries but doesn't do a good job

    Zach
     
    Zach, Aug 4, 2007
    #1
    1. Advertising

  2. Zach <> wrote:
    > Looking for a program that will convert K&R C source files (including
    > headers) to C99 (or at least some early ANSI standard) and it must
    > recognize typedefs and preserve argument promotion; protoize doesn't
    > and cproto tries but doesn't do a good job


    oh (noting of course that non-hypothetical programs are off-topic),
    what sort of problem did you run into with cproto?

    http://invisible-island.net/cproto/

    --
    Thomas E. Dickey
    http://invisible-island.net
    ftp://invisible-island.net
     
    Thomas Dickey, Aug 4, 2007
    #2
    1. Advertising

  3. Zach

    Eric Sosman Guest

    Zach wrote:
    > Looking for a program that will convert K&R C source files (including
    > headers) to C99 (or at least some early ANSI standard) and it must
    > recognize typedefs and preserve argument promotion; protoize doesn't
    > and cproto tries but doesn't do a good job


    Promotion is the hard part, so hard I don't think it
    can be done perfectly. For example, I don't think there
    is *any* way to write a prototyped function equivalent to

    int f(c)
    char c;
    { ... }

    .... because char promotes to int on most platforms but
    to unsigned int on a few. You'd get similar problems with

    int g(x)
    int16_t x;
    { ... }

    .... but I imagine this would be rarer; K&R-style functions
    probably predate the invention of C99 types.

    Can you explain your situation a little more? For
    example, why do you want to introduce prototypes AND
    retain the argument promotions of un-prototyped functions?
    Planning on converting only part of the code (ick)?

    Or attack it from the other side: Explain just what it
    is about the tools you've tried that fails to meet your need.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Aug 4, 2007
    #3
  4. Eric Sosman <> writes:
    > Zach wrote:
    >> Looking for a program that will convert K&R C source files (including
    >> headers) to C99 (or at least some early ANSI standard) and it must
    >> recognize typedefs and preserve argument promotion; protoize doesn't
    >> and cproto tries but doesn't do a good job

    >
    > Promotion is the hard part, so hard I don't think it
    > can be done perfectly. For example, I don't think there
    > is *any* way to write a prototyped function equivalent to
    >
    > int f(c)
    > char c;
    > { ... }
    >
    > ... because char promotes to int on most platforms but
    > to unsigned int on a few.

    [...]

    But that's still legal C99.

    The OP probably wants C99 with prototypes for all functions, but
    that's not quite what he said.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Aug 4, 2007
    #4
  5. Zach

    Chris Hills Guest

    In article <>, Zach
    <> writes
    >Looking for a program that will convert K&R C source files (including
    >headers) to C99 (or at least some early ANSI standard) and it must
    >recognize typedefs and preserve argument promotion; protoize doesn't
    >and cproto tries but doesn't do a good job


    You don't say if it is K&R 1 or K&R2

    K&R 2 is similar to ANSI/ISO C 89/90

    Most of compilers use ISO C95 (C90 + A1 + TC1 + TC2)

    ISO C99 has not really been implemented very widely

    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Aug 5, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kartik
    Replies:
    3
    Views:
    4,010
  2. Peng Yu
    Replies:
    2
    Views:
    726
    Default User
    Sep 29, 2004
  3. Replies:
    13
    Views:
    6,459
    Dave Thompson
    Dec 20, 2004
  4. Replies:
    3
    Views:
    3,698
    Chris Torek
    Feb 20, 2006
  5. Replies:
    3
    Views:
    609
    Keith Thompson
    Mar 31, 2007
Loading...

Share This Page