ANSI C prototypes

D'Arcy J.M. Cain darcy at druid.uucp
Wed Nov 7 00:27:25 AEST 1990


In article <3933.27353319 at cc.helsinki.fi> jaakola at cc.helsinki.fi writes:
>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?
>
>	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
All ANSI compilers that I have used do exactly that.  You do of course
have to declare the function in an ANSI compliant way but once you do
it is effectively prototyped from that point on.  In the above example
replace the first two lines with:

	static void auxiliary_func(int a) /* private helper-function */

The only time that I have to retype (or copy) a prototype is when the
function is used in a different 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.
So that just means we need smarter tools, not that we should stand still
for fear of disturbing something.

>
>After the first line I tell the types of each arg and use comments after
>each args as shown above.
Where suitable I do the same thing:
	int foo(
	int b,      /* the b means ... blahblahblah */
	char *s)    /* the s means ... */

-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   I support gun control.
West Hill, Ontario, Canada         |   Let's start with the government!
+ 416 281 6094                     |



More information about the Comp.lang.c mailing list