How Does 'C' Store Strings ?

Sandy Mustard mustard at sdrc.UUCP
Tue Oct 17 09:34:28 AEST 1989


In article <2157 at avsd.UUCP>, childers at avsd.UUCP (Richard Childers) writes:
> I recently said ...
> 
> 	char vers[CMDBUFSIZ] =		"v1.00 891010 richard childers" ;
> 
> 
> The best help I've gotten to date suggested that I use 'static' storage
> classes for SCCS-type buried ID strings
> 
> One possibility that's occurred to me is that, in a PC environment, the
> designers of the compiler might have decided that string compression was
> a win, much as ( according to many contributors ) Lattice' compiler tries
> to identify and eliminate redundant strings from the resulting image,
> given the significant decrease in space available in an MS-DOS environ-
> -ment.

You may also want to use 

static const char vers.....
       ^^^^^
This may help avoid the redundant string elimination. 

Would not the following be true.

static char string1[] = "ABCD";
static char string2[] = "ABCD";

The compiler could eliminate the redundant strings (when appropriate)

whereas:

static const char string1[] = "ABCD";
static char string2[] = "ABCD";

should force the compiler to store two separate strings. 

(I hope someone will correct me if I'm wrong.:-))

Sandy



More information about the Comp.lang.c mailing list