From: kagel AT quasar DOT bloomberg DOT com Date: Thu, 18 Apr 1996 08:37:47 -0400 Message-Id: <9604181237.AA03084@quasar.bloomberg.com > To: gaghon AT nevada DOT edu Cc: djgpp AT delorie DOT com In-Reply-To: <4l2962$68b@news.nevada.edu> (gaghon@nevada.edu) Subject: Re: static variables Reply-To: kagel AT dg1 DOT bloomberg DOT com From: gaghon AT nevada DOT edu (GEORGE GAGHON) Date: 17 Apr 1996 08:12:50 GMT I have a silly question. In the DJGPP compiler there is a 256k stack for AUTO arrays and vars. How is a STATIC variable different from a AUTO variable, and where is it stored? OK, automatic (local) variables reside on the stack (auto because they are created and destroyed automatically when the function is called/returns), static and global/extern variables reside together in the heap. The only difference between statics and globals (variables declared outside any function but not static) and externs (variables defined in the current module with the extern keyword but declared elsewhere) is name scoping. Statics are only visible in the compilation module within which they are declared. If declared at function scope the name is only visible within that function. Declared outside of any function the name is global to any function within that file but is invisible to functions declared in other files. Globals are declared outside of any function without the static keyword and are visible to any function. To make a global visible to a function define it with an extern keyword within the specific function or outside any function to make it visible to all functions in the file. I hope that this is what you wanted. -- Art S. Kagel, kagel AT quasar DOT bloomberg DOT com A proverb is no proverb to you 'till life has illustrated it. -- John Keats