By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,588 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

K&R -> C99?

P: n/a
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

Aug 4 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Zach <ne****@gmail.comwrote:
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
Aug 4 '07 #2

P: n/a
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
es*****@ieee-dot-org.invalid
Aug 4 '07 #3

P: n/a
Eric Sosman <es*****@ieee-dot-org.invalidwrites:
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) ks***@mib.org <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"
Aug 4 '07 #4

P: n/a
In article <11**********************@x35g2000prf.googlegroups .com>, Zach
<ne****@gmail.comwrites
>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 /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Aug 5 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.