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

The Beach Bum jfh at rpp386.UUCP
Mon Aug 22 03:12:24 AEST 1988


In article <11879 at iuvax.cs.indiana.edu> bobmon at iuvax.UUCP (RAMontante) writes:
>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.

the msc compiler is broken.  the code should compile without error
as written (more or less ...)

as for the Rational behind why this is being done, ask the programmer.
the minimalist coding would be

static z();

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

a possible rationality behind his coding in the fashion he did is
that the functions were actually much larger than what we have above
and he wanted to indicate that the functions x() and y() were both
dependent on z().  as for why z() is declared to be static, any
number of reasons exist.
-- 
John F. Haugh II                 +--------- Cute Chocolate Quote ---------
HASA, "S" Division               | "USENET should not be confused with
UUCP:   killer!rpp386!jfh        |  something that matters, like CHOCOLATE"
DOMAIN: jfh at rpp386.uucp          |         -- apologizes to Dennis O'Connor



More information about the Comp.lang.c mailing list