9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] constant string
@ 2004-03-08 10:15 Prem Mallappa
  2004-03-08 10:27 ` lucio
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Prem Mallappa @ 2004-03-08 10:15 UTC (permalink / raw)
  To: 9fans

hi,

this is my program
------------------------------------------
#include <stdio.h>

int main(void)
{
	char *s = "Hello";
	
	s[2] = 'z';
	
	printf ("%s\n", s);
	
	return 0;
}

------------------------------------------

my question is when i compile this in Linux (gcc) i get a segmentation 
fault at the second statement of main(),
As far as my knowledge i think this is because in 2nd chapter of K&R book
it is being mentioned that
' any thing enclosed between " and " is a string constant' so here i am
changing a constant, and i get a segmentation fault ( and i also noticed
that gcc stores the string Hello in read-only datasegment)

but when i compile the same thing in plan9 C compiler ( both native "8c"
and "pcc" i get a output of "Hezlo")
why this is happenning..

sorry if i am posting to wrong group,
thanks in advance
prem


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-03-12  8:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-08 10:15 [9fans] constant string Prem Mallappa
2004-03-08 10:27 ` lucio
2004-03-08 10:53 ` [9fans] " Richard Bos
2004-03-08 14:13 ` [9fans] " dbailey27
2004-03-08 15:22   ` C H Forsyth
2004-03-09  3:41     ` Russ Cox
2004-03-09  9:17       ` Charles Forsyth
2004-03-08 22:40 ` William Josephson
2004-03-10  9:47 ` [9fans] " Peter Pichler
2004-03-12  8:56   ` Bruce Ellis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).