void procedures
Doug Gwyn
gwyn at smoke.brl.mil
Sat Nov 10 16:19:08 AEST 1990
In article <9944 at helios.TAMU.EDU> swarnam at cs.tamu.edu (Prabaharan Ilanji Swarnam) writes:
>Recently one of my friends had a program in which there had
>been some procedure calls like
> free_vectori(x,y,z);
> .....etc etc...
>Thes procedures were included in a header file which contained
>them in the following format
> void free_vectori(a,b,c);
> .....etc etc...(with no body for the above)
>I was under the impression that that call for free_vectori() would
>not return any changes to the arguments or induce any side effects.
>But she argued that the call certainly made some changes to the
>arguments indirectly.
>Is that possible ?
>The void procedure format had no body so I understand that the
>parameters cannot be used or modified. Then why are those kind of
>void procedures used ?
Your problem is a lack of precision in the concepts involved.
free_vectori(x,y,z);
is an invocation of a function named "free_vector" (technically, via
a pointer to the function that was derived from the name), with
actual arguments that in this particular case are the values of simple
expressions, each consisting simply of the evaluation of the contents
of a variable (named "x", "y", or "z").
Before invoking a function, in most cases (I recommend in all cases)
it needs to be properly declared. The declaration associates a specific
type with the identifier that designates the function. The header file
that you mention does not contain "procedures"; it contains declarations
for the functions. Such a declaration does not in itself cause the
function to come into existence; only a definition provided elsewhere
can do that. The declaration
void free_vectori(a,b,c);
simply says that after that point in the translation unit (source file)
the identifier "free_vectori" will designate a function taking three
arguments each of type int -- it would have been better style to write
extern void free_vectori(int a, int b, int c);
-- and not returning a value. (Not returning a value does not mean
that no computation is performed by the function!)
Somewhere else, perhaps in a library or in another object module linked
together with the object resulting from compiling the source we have
been discussing, there must be a definition for every function that is
actually invoked. Usually the definition is produced from a C source
that defines the function, for example:
void free_vector(int p, int q, int r) {
printf("%d %d %d\n", p, q, r);
}
In this example, "p". "q", and "r" are identifiers that act as parameters
for the definition; whenever the function is invoked at run time, the
actual argument values are bound to these parameters before the body of
the function is executed.
There is no such thing in C as a bodyless definition for a function.
More information about the Comp.lang.c
mailing list