Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ukma!gatech!seismo!mimsy!meyer From: meyer@mimsy.UUCP Newsgroups: comp.lang.c Subject: Re: static variables Message-ID: <6887@mimsy.UUCP> Date: Tue, 2-Jun-87 19:48:28 EDT Article-I.D.: mimsy.6887 Posted: Tue Jun 2 19:48:28 1987 Date-Received: Fri, 5-Jun-87 01:11:49 EDT References: <7653@brl-adm.ARPA> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 42 In article <7653@brl-adm.ARPA>, jfjr@mitre-bedford.arpa writes: > > Are character strings local to a function static?? > > given this > > int do_something() > { > char * some_string = "some string" > do_things; > return(some_int); > } > > is some_string static?? > > Jerry Freedman,Jr Local variables like "char *some_string" are, by default, declared to be automatic. The string it points to, however, is in static memory. That is, each time function do_something is called, a new variable named some_string is created on the run-time stack, and is initialized to point to the beginning of "some string" (which is in static memory, whose address is calculated at compile-time). some_string comes and goes as do_something is entered and left, but the string "some string" exists throughout the execution of the program. However, since "some string" is defined inside do_something, no other program unit outside of do_something can (legitimately) get access to "some string". It may be useful to check Kernighan & Ritchie, pp 99-100. Hope this helps. Feel free to send me mail if you're still confused. John -- John R. Meyer 6100 Westchester Park Dr. Apt. 420 College Park, MD 20740 (301) 474-8271