Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!lll-winken!csustan!polyslo!sdejarne From: sdejarne@polyslo.UUCP (Steve DeJarnett) Newsgroups: comp.lang.c Subject: Re: static stuff... Message-ID: <722@polyslo.UUCP> Date: Wed, 18-Nov-87 20:20:23 EST Article-I.D.: polyslo.722 Posted: Wed Nov 18 20:20:23 1987 Date-Received: Sat, 21-Nov-87 11:55:24 EST References: <3011@sigi.Colorado.EDU> Reply-To: sdejarne@polyslo.UUCP (Steve DeJarnett) Organization: Cal Poly State Univ,CSC Dept,San Luis Obispo,CA 93407 Lines: 30 In article <3011@sigi.Colorado.EDU> swarbric@tramp.Colorado.EDU writes: >First, what is the significance of making a static function? Static functions are only callable in the source file that they are defined in. This way, you can make protected functions (although, if you only have one source file, their use makes less sense). >Second, aren't all global variables automatically static. Is there any >reason to explicitly call them static? All automatic variables are NOT static. Static variables declared inside a function retain their value between function calls (i.e. if a function with a static variable is called more than once, the value of the static variable from the first call is preserved.), whereas automatics lose their value between function calls (they are re-initialized at each call). If you only call a function once, then it may appear that the automatics you defined behave just like statics, but there is a difference. If you define static variables outside of a function body, they are only visible to functions BELOW themselves in the source file. They are not visible to functions in different source files. I'm fairly sure all of this is correct, but if not, I'm sure some C guru will let me know :-). Hope this helps. ------------------------------------------------------------------------------- | Steve DeJarnett | ...!ihnp4!csun!polyslo!sdejarne | | Computer Systems Lab | ...!{csustan,csun,sdsu}!polyslo!sdejarne | | Cal Poly State Univ | ...!ucbvax!voder!polyslo!sdejarne | | San Luis Obispo, CA 93407 | | ------------------------------------------------------------------------------- #include