External Functions
Lars Wirzenius
wirzenius at cc.helsinki.fi
Sat Mar 16 22:51:16 AEST 1991
In article <8146 at rsiatl.Dixie.Com>, stan at Dixie.Com (Stan Brown) writes:
[Edited for brevity --Lars Wirzenius]
> Which of the folowing would be better & why
(1)
> extern void foo();
> void func1() { ... }
> void func2() { ... }
(2)
> void func1() { extern void foo(); ... }
> void func2() { extern void foo(); ... }
(1) is better, since the declaration needs to be written only once, so
there is less of a chance to introduce bugs when (not if) you change the
function declaration. You could improve on (1) by putting its
declaration (prototype if you have an ANSI compiler) into a header file,
and #including that into any source file that calls foo, and also into
the file that defines it (this is a handy way to ensure that
declarations and definitions stay in sync).
--
Lars Wirzenius wirzenius at cc.helsinki.fi
More information about the Comp.lang.c
mailing list