Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > K&R -> C99?

Reply
Thread Tools

K&R -> C99?

 
 
Zach
Guest
Posts: n/a
 
      08-04-2007
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

 
Reply With Quote
 
 
 
 
Thomas Dickey
Guest
Posts: n/a
 
      08-04-2007
Zach <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      08-04-2007
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
http://www.velocityreviews.com/forums/(E-Mail Removed)lid
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      08-04-2007
Eric Sosman <(E-Mail Removed)> 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) (E-Mail Removed) <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"
 
Reply With Quote
 
Chris Hills
Guest
Posts: n/a
 
      08-05-2007
In article <(E-Mail Removed) .com>, Zach
<(E-Mail Removed)> 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 /\/\/\/\/
/\/\/ (E-Mail Removed) www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments