converting "classic c" to "ansi c"

Scott Drysdale scotty at ziggy.UUCP
Sat Feb 25 16:20:19 AEST 1989


first, the background...

at work, we're developing a hunk of code for a piece of telecommunications
test gear in C.  so far we've been using a "classic c" compiler (ie, k&r 1).
we recently got a new compiler which is some flavor of ansi.  we wish to
change the old c code to new c code so that we a) don't get thousands of
warnings/errors due to the lack of proper type definitions, and b) we end
up with ansi-style prototyped function declarations.

the question...

has anyone come across or written a set of utilities to perform the above
translations?  essentially it would involve moving the parameters for
a function declaration into the parentheses, ie
	main(argc, argv)
	int argc;
	char *argv[];
becomes
	main(int argc, char *argv[])
and perhaps also try to deduce whether the function really is returning
'int' or should be 'void' based on whether it tries to return a value (er,
extend that to include the type of the value it tries to return).  of course,
it should also squirt out an 'extern' version of each declaration suitable
for inclusion in a .h file.

as to variable declarations, it would be nice to have the thing insert
proper casts in the code where necessary to prevent the compiler from
bitching (this would require that the translation program essentially
act as the front end of a compiler in order to analyze the assignments/
references).  of course, it would produce a log which we could examine to
determine if any of the transformations it performed should be undone or
are bugs.

we also have the additional requirement that any initialized structures
or variables have the 'const' modifier, since we intend to squirt them
directly into ROM.  of course, the 'extern' version of these would also
carry the 'const.'

some specifics...

the "old" compiler in question is HP's 64000-UX cross compiler for the 80186
running under HP-UX on a 9000/350 machine.  the "new" compiler is the AXLS
cross compiler for the same target running on the same host.

any pointers would be appreciated!

  --Scotty
Telecommunications Techniques Corp, Germantown MD



More information about the Comp.lang.c mailing list