ANSI C prototypes
John Stanley
stanley at phoenix.com
Wed Nov 7 04:41:13 AEST 1990
rjc at uk.ac.ed.cstr (Richard Caley) writes:
> In article <3933.27353319 at cc.helsinki.fi> jaakola at cc.helsinki.fi writes:
>
> 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;
> {
> The point is, why should I have to tell the compiler twice the type of
> auxiliary_func?
>
> You don't. In the above case you havn't even told it once. If you
> did...
No, he most certainly DID tell the compiler the type of the function.
This is one of those prior art things that the ANSI committee had to
maintain. It is called a function definition (old style), and has scope of
'global to file'. He even told the compiler the type of arguement a. The
compiler should most certainly know the type of the function when it sees
it later within the other function. Because it is the old-style
definition, the compiler is not required to keep track of the type of the
parameter a required by that fucntion, so there will be no type checking
on a. There most certainly should be type checking on the function itself.
And the compiler should absolutely not generate an error on this syntax.
> static void auxiliary_func(int a)
>
> {
>
> you wouldn't need to type anything more. Or if you did that would be a
> massive compiler misfeature. This even saves you a couple of
> characters :-)
Moving the declaration of a into the parameter list converts this
definition into new style. The only difference between old and new in
this case is that the compiler is now required to type check the
_parameter_ passed to a.
Through other communication with Mr. Jaakola, it turns out that this
is a misfeature of Microsoft C.
<> "Aneth! That's a charming place!" "You've been to Aneth?"
<> "Yes, but not yet." -- The Doctor and Seth, "The Horns of Nimon".
><
<> "Sanity check!" "Sorry, we can't accept it, it's from out of state." - me
More information about the Comp.lang.c
mailing list