Function declarations (was: MSC v5.1 Bug???)

RAMontante bobmon at iuvax.cs.indiana.edu
Sun Aug 21 02:31:58 AEST 1988


Craig Dawson asks about a program in which two routines try to call a
third, somewhat as follows:

x() { static z(); z(); }
y() { static z(); z(); }

static z() { ; }

(MSC apparently chokes; BTW, TurboC accepts it.)  My question is... Why
declare z() inside the functions x() and y()?  It doesn't make sense
that the name "z" should be localized to these code blocks, since it
has to be global to the entire file (at least) anyway.  Nor do I see
the value of making it a static name, since it references an object
that can't go away or be "reclaimed" outside of x() or y(), namely a
function.  Craig's "fix", declaring static z() prior to and outside of
both x() and y() (an almost-protoype kind of declaration), seems like
the only natural thing to do.

Note:  I understand why local variables are good.  But it seems pointless
to treat the function name as "local", since it must refer to a nonlocal
object.  What am I missing?  Is there a relevant section of K&R I should
read?
-- 
--    bob,mon			(bobmon at iuvax.cs.indiana.edu)
--    "Aristotle was not Belgian..."	- Wanda



More information about the Comp.lang.c mailing list