Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!cornell!uw-beaver!milton!ogicse!intelhf!ichips!inews!pima!bhoughto From: bhoughto@pima.intel.com (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: doing nasty things with internal static variables Keywords: C, crossreference Message-ID: <3306@inews.intel.com> Date: 23 Mar 91 03:53:55 GMT References: <1991Mar19.164037.7421@intellistor.com> <1991Mar19.183920.18911@rice.edu> <78hW01XR47Gy00@amdahl.uts.amdahl.com> Sender: news@inews.intel.com Distribution: usa Organization: Intel Corp, Chandler, AZ Lines: 29 In article <78hW01XR47Gy00@amdahl.uts.amdahl.com> lamont@amdahl.uts.amdahl.com (Duane Richard LaMont) writes: >Much to her surprise, string a was always identical to string b >regardless of the values of x and y. I pointed out that a and >b both pointed to the static buffer within foo which was overwritten >on each call. So, I was feeling pretty good about myself until the >next week when I wrote something like this: Why would you feel good about yourself? She had to search out the author rather than find the answer in the documentation. Did you update the docs? That'd be something to be happy about. >Also note that, at least on my system, asctime uses a static return >buffer and has this caveat listed on the man page. strtok(3) also makes much noise about its using static space to store the token-string. The converse of this situation is a function that operates on the string pointed to by something you passed it, then returns a pointer back to you that presumably points to the result of the operation, when the result of the operation is that your string's been munged. Most of the stuff does this (so does strtok(3), actually, so it gets you both coming and going). --Blair "Kinda like when you think all you did was post an example..."