Function prototype generator

dalenber at p.cs.uiuc.edu dalenber at p.cs.uiuc.edu
Fri Jun 24 09:34:00 AEST 1988


For the past few weeks I have been writing a C-function prototype
generator. I would say that it is now about 85% finished; it does just about 
everything I want it to do. The only area where it is really lacking is in
handling array arguments to functions. For example, given the function
definition:

	int func (arg)
	char arg[];
	{
	/* ... */
	}

It will generate the prototype:
	extern int func (char arg[]);

For this case, it is obvious that the argument in the prototype should
be "char *arg", but what about multi-dimensional arrays? Should:

	int func (arg)
	int arg[][10];
	{
	/* ... */
	}

produce:
	extern int func (char **arg); ?

I seem to remember some notes about "pointer to array" being a legal type
in "ANSI C"; how would definitions of this type differ from those above?
Would it be legal to define a function returning a pointer to an array of
int? And if so, how would such a thing be written? Should I just convert
all array references to pointer references?

If any ANSI-C gurus can answer these questions, I'll be eternally greatful
(well, maybe not eternally :-) ).


The second reason I am posting this note is ask the C community at large,
"what features would you want in a prototype generator?"

At present, the program accepts function definitions in either the old 
fashioned style used in the examples above, or the new ANSI style, 
formatted in any manner, and massages the information into prototype
format. It produces output in the form

	#ifdef __STDC__
	<function prototypes>
	#else
	<old-fashioned function allusions>
	#endif

The token "__STDC__" can be set at run time to be any symbol.
Also at run time, options can be given to exclude any static functions
from the output, as well as the prototype for "main".

What I'd like to know is, what else should it do? I'm particularly
unsure how to handle multiple files. Should I generate one large
output on standard-output, or into a user specified file; or should
I automatically put the output for "file.c" into "file.p" (or something
of that nature). A good user interface is very important, and I know
that what I find natural may seem odd to others.

Please send me your comments, and ideas. In a few weeks, after I've
finished implementing everything, I'll post the source in
comp.sources.{unix or misc} for all the world to enjoy.

Much thanks in advance for any help I receive.


Russel Dalenberg

	UUCP:	{pur-ee,convex,ihnp4}!uiucdcs!dalenber
	ARPA:	dalenber at p.cs.uiuc.edu
	CSNET:	dalenber at UIUC.CSNET



More information about the Comp.lang.c mailing list