array init'ing, static or auto?

Wm E Davidsen Jr davidsen at crdos1.crd.ge.COM
Thu Nov 16 01:52:23 AEST 1989


  If you are not going to modify the char array, by all means make it
static. Many compilers will not allow you initialize the array unless it
*is* static, although ANSI compilers should. You might want to init to a
char pointer, as this takes less time in init, may take more in
execution depending on what you do with it;

foo() {
  char str1[] = "abcd";		/* make not work on old compilers	*/
  static char str2[] = "abcd";	/* should be portable			*/
  char *str3 = "abcd";		/* should be portable			*/

  /* code here */
}

  Note that these are NOT completely the same, although most uses with
or without subscripts should generate the same results. There are
performance tradeoffs and if you declare an array instead of a pointer
you can't modify it (obviously).
-- 
bill davidsen	(davidsen at crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
"The world is filled with fools. They blindly follow their so-called
'reason' in the face of the church and common sense. Any fool can see
that the world is flat!" - anon



More information about the Comp.lang.c mailing list