[comp.lang.c] converting "classic c" to "ansi c"

scotty@ziggy.UUCP (Scott Drysdale) (02/25/89)

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

suitti@haddock.ima.isc.com (Stephen Uitti) (03/07/89)

In article <173@ziggy.UUCP> scotty@ziggy.UUCP (Scott Drysdale) writes:
>first, the background...
>
>at work, we're developing a hunk of code for a piece of telecommunications
>test gear in C.
>the question...
>has anyone come across or written a set of utilities to perform the above
>translations?

Microsoft C 5.0 for the PC has a utility which will generate
function prototypes.  I have it, but have not used it.
MSC can be had for $300 or so...

>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...

How portable is the original code?  If it used to work does it
need fixing?

>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.'

Handy, but I doubt that const stuff will get put into ROM automatically.
Typically you have to do some linker magic anyway...

	Stephen Uitti, suitti@ima.ima.isc.com

bph@buengc.BU.EDU (Blair P. Houghton) (03/08/89)

Speaking of which, (and I'm a bit dismayed that I hadn't thought to ask
sooner) when is ANSI going to finalize the standard?  I'm beginning to
worry about conforming, and I'd like to know when to start trusting the
available standardlets (i.e., when is it too late for them to be
changed easily?).

What are the scheduled date of publication, the expected date of
publication, the likely date of publication, and the likely date that
the thing will be obsolete?

				--Blair
				  "Yes, I know, the answer to the
				   last one is '1978'..."

gwyn@smoke.BRL.MIL (Doug Gwyn ) (03/08/89)

In article <2214@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>Speaking of which, (and I'm a bit dismayed that I hadn't thought to ask
>sooner) when is ANSI going to finalize the standard?

It is expected that they will more or less automatically ratify it after
X3 approves the pANS.  X3 should have just completed balloting on the
pANS that X3J11 sent them; I don't yet know the outcome of the balloting.
(It will be really annoying if some X3 member objected at this stage,
given all the time and effort that went into resolving objections during
the past couple of years.)

If the pANS has passed X3, ANSI should get around to approving it and
publishing the standard within a few months.

>... I'd like to know when to start trusting the available standardlets
>(i.e., when is it too late for them to be changed easily?).

It's already too late for the pANS to be changed easily.
If for some reason a change is required at this stage, it will be a
major hassle.  Many X3J11 committee members are winding down their
involvement.

>What [is] ... the likely date that the thing will be obsolete?

Not for several years, and even then if there is a revised standard
it is likely to be upward compatible with this one (i.e. existing
conforming applications would continue to be supported, and extensions
to the language and library may be allowed or required beyond the
initial standard).

flee@shire (Felix Lee) (03/13/89)

I don't suppose anyone has the reverse tool, take an ANSI C program
and spit out an unansified, deprototyped version?
--
Felix Lee	flee@shire.cs.psu.edu	*!psuvax1!shire!flee

wietse@wzv.UUCP (Wietse Z. Venema) (03/14/89)

In article <4360@psuvax1.cs.psu.edu> flee@shire.cs.psu.edu (Felix Lee) writes:
>I don't suppose anyone has the reverse tool, take an ANSI C program
>and spit out an unansified, deprototyped version?

Yes, there is.  It is called `agcpp', a /lib/cpp replacement that turns
ansi c prototypes into classic c declarations.  The program was posted
recently in comp.os.minix by Alistair G. Crooks <agc@nixbln.UUCP>.
-- 
work:	wswietse@eutrc3.uucp	| Eindhoven University of Technology
work:	wswietse@heitue5.bitnet	| Mathematics and Computing Science
home:	wietse@wzv.uucp		| 5600 MB Eindhoven, The Netherlands

throopw@agarn.dg.com (Wayne A. Throop) (03/14/89)

> flee@shire (Felix Lee)
> I don't suppose anyone has the reverse tool, take an ANSI C program
> and spit out an unansified, deprototyped version?

I have heard that there is a tool which will do this.  It is called
"cfront".  It also does a few other things.  It is available from AT&T.

--
Beware of the Turing tar-pit in which everything is possible
but nothing of interest is easy.
                                        --- Alan J. Perlis
--
Wayne Throop      <the-known-world>!mcnc!rti!xyzzy!throopw