Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: array init'ing, static or auto? Message-ID: <1989Nov12.154259.9425@virtech.uucp> Date: 12 Nov 89 15:42:59 GMT References: <2679@dogie.macc.wisc.edu> Organization: Virtual Technologies Inc. Lines: 26 In article <2679@dogie.macc.wisc.edu>, yahnke@vms.macc.wisc.edu (Ross Yahnke, MACC) writes: > If I init a char array declared inside a function with a string: > wubba() > { char wubbaStr[] = "wubba"; > ... > when does actually get init'ed? When the function is called? pcc gives an error about "no agregate initializations..." gcc compiles it and initializes the data for each call to the function. If your compiler accepts it, it will probably initialize it for each iteration of the function. > If wubba() got called a few thousand times, would it be faster > to make wubbaStr static instead? > wubba() > { static char wubbaStr[] = "wubba"; Yes, if you don't change wubbaStr[]. However if you change wubbaStr[] the string will not be reset to it's original value the next time through. -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+