array init'ing, static or auto?

Conor P. Cahill cpcahil at virtech.uucp
Mon Nov 13 02:42:59 AEST 1989


In article <2679 at dogie.macc.wisc.edu>, yahnke at 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     |
+-----------------------------------------------------------------------+



More information about the Comp.lang.c mailing list