Xref: utzoo comp.lang.c:11980 comp.sys.ibm.pc:18266 Path: utzoo!utgpu!water!watmath!clyde!ima!haddock!suitti From: suitti@haddock.ima.isc.com (Steve Uitti) Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: Re: Function declarations (was: MSC v5.1 Bug???) Message-ID: <6314@haddock.ima.isc.com> Date: 22 Aug 88 16:07:28 GMT References: <10102@genrad.UUCP> <11879@iuvax.cs.indiana.edu> <5680@rpp386.UUCP> Reply-To: suitti@haddock.ima.isc.com (Steve Uitti) Organization: Interactive Systems, Boston Lines: 58 In article <5680@rpp386.UUCP> jfh@rpp386.UUCP (The Beach Bum) writes: >In article <11879@iuvax.cs.indiana.edu> bobmon@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()? Supporting other peoples code is more difficult than supporting your own. A thirty file program where everything (that can be) is declared static is much easier to support than one that doesn't. "ctags", "grep", and cxref only do so much for you. The tighter the scope of each variable and function, the better. I generally try to declare the functions before all uses: static z(a) int a; { ; } static y() { z(5); } static x() { y(); z(); } main() { x(); } Kind of reminds you of Pascal (except that you can tell where "main" starts). The complexity of a program at any point seems to be tied exponentialy to the number of variables and functions available to it at that point. Unfortunately, the compilers that I've used that support prototypes don't "automatically generate" them using this style. If I want prototypes for the above, I need: static z(a) int a; { ; } #ifdef PROTOTYPES_SUPPORTED static z(int a); /* prototype for z() */ #endif /* PROTOTYPES_SUPPORTED */ static y() { z(5); } static x() { y(); z(); } main() { x(); } Which is too bad, since it really has all the info it could possibly want, and I'll probably just screw up the prototype (since I can). On PDP-11's, the linker (ld) can run out of symbol space for the symbol table if you don't do this. Generally, the larger editors that have been ported to this machine got hundreds of routines declared "static", just to allow compilation. This wasn't "bad". It made the products easier to maintain. Another favorite is this: y() { z(); } static z() { ; } This often yields something like "redeclaration of z". The first reference defaults to something like "extern int z();" for a declaration. I've always thought that this was a language feature. It encourages better behaviour without requiring it. Of course the following is fine: static z() { ; } y() { z(); } Stephen