Protoize/Unprotoize (was: ANSI C to K&R syntax converter)

Martin Minow minow at mountn.dec.com
Tue Jun 5 04:57:05 AEST 1990


In article <1990May31.214655.18960 at csrd.uiuc.edu> pommerel at sp14.csrd.uiuc.edu
(Claude Pommerell) writes:
>
>I am looking for a portable converter from ANSI C syntax to
>traditional Kernighan&Ritchie syntax.

I've had good results by writing prototypes using the following process:

	/*
	 * prototype.h
	 */
	#ifdef _STDC_
	#if _STDC_ != 0
	#define _(x)	x
	#endif
	#endif
	#ifndef _STDC_
	#define _(x)	()
	#endif

	/*
	 * All functions are specified here:
	 */
	int		sample _((int, char *, struct foo));

The actual definition of a function uses the old -- but still valid -- syntax:

	int
	sample(i, cp, foostruct)
	int		i;
	char		*cp;
	struct foo	foostruct;
	...

The advantage is that your code remains maximally portable, yet you have
the advantage of type-safety where available.  The disadvantage is that
you *must* not presuppose other Ansi features, such as automatic conversion
of variables.  Also, the above doesn't handle variable-length argument lists.
(Also, strictly speaking, the macro '_' is reserved to the implementation).

The above should be portable to all C implementations since around 1978.

Martin Minow
minow at thundr.enet.dec.com



More information about the Comp.lang.c mailing list