ANSI C prototypes

jaakola at cc.helsinki.fi jaakola at cc.helsinki.fi
Mon Nov 5 20:38:33 AEST 1990


In article <RJC.90Nov3153129 at brodie.uk.ac.ed.cstr>, rjc at uk.ac.ed.cstr (Richard Caley) writes:
> Since there is, as far as I know, no difference between the prototype
> and the definition except for the `;', there is no extra typing to do.
> Just copy the definition.

Why do *I* have to do the copying for all my functions, while there's
the compiler which a) is supposed to work for me and not vice versa
             and   b) should know ANSI peculiarities better than I do?

It's okay for me to make an include file, where I declare functions that
are visible to other modules. But consider the following example:

	static void auxiliary_func(a) /* private helper-function */
	int a;
	{
		...
	}

	void visible_fun(b)
	int b;
	{
		...
		auxiliary_func(b+1);   /* should be checked */
		...
	}

The point is, why should I have to tell the compiler twice the type of
auxiliary_func? The prototype should be necessary only if I make a
forward reference to make it easier for the compiler to check types in a
single pass. I think the function definition tells unambiguously the
types, so I should not have to watch warnings such as "function
definition used as a prototype" (Microsoft C 5.1).

Ok, I could turn off such warnings in Microsoft C 5.1, but this turns
off some useful checks as a side-effect! Please, Microsoft, make a
"prototypes-off" switch into Microsoft C for me!

I do not want to bother keeping prototypes of such axiliary
helper-functions up-to-date. "You could use an automatic prototype
builder," I hear you say. Yeah, I could, but why couldn't that builder
be built into the compiler, so that I didn't have to burden my brains to
use it? After all, those helper-functions tend to change much when I
fine-tune the implementation of my module.

Another ANSI-misfeature is the ability to make declarations such as:

	int foo(int b, char *s)

I like much more the old style

	int foo(b,s)
	int b;      /* the b means ... blahblahblah */
	char *s;    /* the s means ... */

This is better, because you can have function name and args on the same
line, so that you can query all function names by grep-like tools (grep
outputs only single lines, which is very compact and - I think -
readable format). If you have much args, this way you can still put all
of them on a single line.

After the first line I tell the types of each arg and use comments after
each args as shown above.



More information about the Comp.lang.c mailing list