doing nasty things with internal static variables

Dwayne Jacques Fontenot fontenot at rice.edu
Wed Mar 20 04:39:20 AEST 1991


Hello,

I have found myself doing this because it works, but I am curious if it
is a common practice or if it is highly likely to get me into trouble:

char *foo()
{
  static char string[64];

  ...
  return(string);
}

I am concerned about this because though I know that that static variable
is guaranteed to always be there for the function containing it, it is
not really guaranteed to be there (in memory) at any other time
(correct me if I'm wrong).

I have used this on ANSI compilers on diverse architectures with no problems
yet, and it's just so damned *convenient*.

Thank you for your time,
Dwayne Fontenot (fontenot at comet.rice.edu)



More information about the Comp.lang.c mailing list