`static'

Jeff Beard jbeard at quintus.uucp
Sat Aug 6 09:09:12 AEST 1988


% Finally, returning to string constants: these are unnamed objects, and
% hence the scoping rules for names are irrelevant.  There simply is no
% name to be scoped.  The objects do, however, have static storage duration:
% they exist at all times.  Thus, once you have a pointer to a string
% constant, you can follow that pointer at any time.  The string shall
% not vanish from underfoot, unless the whole program vanishes with it.

1) program scoped static char * foo may be altered anywhere by any procedure
   and thus the original string reference will be lost to all, even though 
   the string it self persists.

	static char * header;

	header = "  Center Heading For Report  ";

	....
	printf(header);	/* performs as expected */
	....

	header = "  Center Footing For Report  ";
	....

	printf(header);	/* yields a FOOTING as a Header ... OhMy! */

2) which brings up another storage class often forgotten altogeter:

	READONLY as in a format string given for printf()

	printf("text %c not of type %s\n" args, ..);

	xstr() collects said strings to reduce storage costs at possible
	expense of memory thrashing to get at a non-local page.



More information about the Comp.lang.c mailing list