ANSI C prototypes

Walter Bright bright at nazgul.UUCP
Fri Nov 9 05:53:13 AEST 1990


In article <3933.27353319 at cc.helsinki.fi> jaakola at cc.helsinki.fi writes:
/	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).

In Zortech, the first function declaration does result in a prototype
being declared (internal to the compiler) and all future uses of
auxiliary_func are checked against that prototype.

In fact, the first use of a function, in the absence of a prototype,
causes a prototype to be generated for that function based on the
default argument promotion rules. This is not ANSI behavior, and can
be disabled with the -P switch, but is very useful in checking for
errors in old K&R code.

The -r switch, strict prototyping, is also available, which enforces a
rule that all uses of a function must have a prototype in scope for it.
I use this switch for all my code, and recommend its use, as it results
in the bugs being caught at the earliest possible time (when they are
the cheapest to fix!).



More information about the Comp.lang.c mailing list