Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!ucsd!orion.cf.uci.edu!paris.ics.uci.edu!nagel From: nagel@paris.ics.uci.edu (Mark Nagel) Newsgroups: comp.lang.c Subject: Re: string assignment in C Message-ID: <790@paris.ics.uci.edu> Date: 17 Oct 88 02:13:01 GMT References: <1988Oct11.143728.28627@gpu.utcs.toronto.edu> <6777@chinet.chi.il.us> <1414@imagine.PAWL.RPI.EDU> Sender: news@paris.ics.uci.edu Reply-To: nagel@paris.ics.uci.edu (Mark Nagel) Organization: University of California, Irvine - Dept of ICS Lines: 38 In-reply-to: kyriazis@rpics (George Kyriazis) In article <1414@imagine.PAWL.RPI.EDU>, kyriazis@rpics (George Kyriazis) writes: |In article <6777@chinet.chi.il.us> john@chinet.chi.il.us (John Mundt) writes: |>Each string, |>"first" and " is:" are reserved by the compiler as unnamed strings |>somewhere in memory. ...... | |My question is: Are strings like " is:" volatile or not? |When you say p2 = " is:", are you sure that the string will remain in |memory or the optimizer will decide to put something else there since |the string is basically a constant used only once?? Of course not! That would be analogous to having the 2 in: x = 2; change at some point in the program since it is "basically a constant." Also, *all* code has the potential for being executed more than once through function calls (well, not global variable initialization, but all code in functions). |I also have the idea that if you say | p1 = "abc"; | p2 = "abc"; |p1 and p2 will have different value, since the strings are not the same |(they have the same contents, but physically should be different). |Is that a right assumption? No. Some compilers will treat them as different objects (i.e. you get two distinct pointer values for the two string constants). Other's will optimize the program's space usage by sorting and uniq'ing all of the strings so that different string constant references all have the same physical address. This is fine since constant strings should be read-only objects. Mark D. Nagel UC Irvine - Dept of Info and Comp Sci | The probability of someone nagel@ics.uci.edu (ARPA) | watching you is proportional to {sdcsvax|ucbvax}!ucivax!nagel (UUCP) | the stupidity of your action.