Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!atha!aunro!alberta!cpsc.ucalgary.ca!yogi.hsc.ucalgary.ca!janus.mtroyal.ab.ca!phd!phil From: phil@phd.UUCP (H Phil Duby) Newsgroups: comp.lang.c Subject: Re: Prototypes local or global opinions wanted Summary: try static qualifier Message-ID: Date: 25 Jun 91 16:49:08 GMT Followup-To: comp.lang.c Organization: Priviate Amiga Site Lines: 49 In article <1991Jun21.004933.4197@athena.mit.edu> scs@adam.mit.edu (Steve Summit) writes: > In article <1991Jun20.202241.7531@msuinfo.cl.msu.edu> draper@buster.cps.msu.edu (Patrick J Draper) writes: > >I'm interested in what others think of the practice of declaring > >function prototypes locally within a procedure. > >The advantage to the local declaration that I can see is that an > >unintentional call to bar() will be flagged by the compiler. I prefer to > >use the global declaration because if the definition of bar should > >change, there's one place to change the prototype. > >Any other opinions? > > Most certainly. If prototypes are used, they MUST be placed in ^^^^ ??? > header files (which of course is usually tantamount to "global > placement"), and then #included by all source files in which the > function(s) is called, AND in the source file where the function > is defined. This way, there's *really* only one place to change > the prototype, and the compiler can check the prototype against > the definition. Another alternative that depends both on the intended usage, and programming style (no flames on that please) coming up :-) If the function you want to prototype (VERY good idea IMHO) is used by a set of other functions that can be convienently grouped together into a single source file, seperate from other functions that should not call the function, declare the prototype global in that source file, but with the static qualifier. Functions in other files will not see the definition, and calls to the function will generate the same errors as if the function was only declared locally. For purists who insist prototypes should also be declared in a header file that is #included by all source files for a program / system (producing global definitions), use the (also talked/beaten to death) option of putting #ifdef #endif pairs around the prototype (with or without the static qualifier), and provide the appropriate define only in the source file(s) that SHOULD be calling the function. This can be both the best and worst option depending on lots of other considerations, mostly to do with personal preferences / in house standards / conventions / practices / size of project / ... I am not promoting any of these as the correct method. Just pointing out another USEABLE alternative that can work in some situations. I don't think we need another flame war. Flames to dev.null, or email if you must. [... normally (IMHO) correct stuff deleted ...] > Steve Summit > scs@adam.mit.edu H. Phil Duby uunet!keyword!calgary!ajfcal!mtroyal!phd!phil (AMiga Users of Calgary) AMUCexpress BBS - 650 meg PD Software Fido net node 1:134/27 (403) 282-5137/5171/5224/5238 3/12/24/24 MNP bps