Are strings local?

Jim Reid jwr at scotty.UUCP
Fri Aug 5 00:04:50 AEST 1988


In article <652 at m10ux.UUCP> rgr at m10ux.UUCP (Duke Robillard) writes:
<
<During my search about this locality of statics business, I discovered
<a pretty bizarre thing about strings.  I dunno if it's just my System
<V compiler or what, but you can write to strings (since they're just
<static arrays of characters?) Like:
<
<main() 
<{
<	char *p;
<
<	p= "abc";
<	p[2]= 'd';
<	printf("%s\n", p);   /* this will print "abd\n" */
<
<        /* or, if you'd like to be even more obscure... */
<	(p= "def")[2]= 'x';
<	printf("%s\n", p);   /* this will print "abx\n" */
<}
<
<Pretty weird, huh?

Could just be your compiler.
I tried it on my system(SUN 3/75 with SUN UNIX 4.2 release 3.5) &
got "dex" where you got "abx".

-- 

Jim Reid	{ames,cmcl2,rutgers}!rochester!kodak!fedsys!wally!jwr

--



More information about the Comp.lang.c mailing list