doing nasty things with internal static variables

Blair P. Houghton bhoughto at pima.intel.com
Sat Mar 23 13:53:55 AEST 1991


In article <78hW01XR47Gy00 at amdahl.uts.amdahl.com> lamont at 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 <string.h>
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..."



More information about the Comp.lang.c mailing list