K&R -> C99?

Z

Zach

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
 
T

Thomas Dickey

Zach said:
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/
 
E

Eric Sosman

Zach said:
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.
 
K

Keith Thompson

Eric Sosman said:
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.
 
C

Chris Hills

Zach said:
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
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top