Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac.programmer Subject: Re: Quick ThinkC String question... Message-ID: <10274@hoptoad.uucp> Date: 16 Feb 90 09:12:12 GMT References: <77108@tut.cis.ohio-state.edu> <20011@bellcore.bellcore.com> <1990Feb14.210352.28118@oracle.com> Reply-To: tim@hoptoad.UUCP (Tim Maroney) Organization: Eclectic Software, San Francisco Lines: 43 In article <1990Feb14.210352.28118@oracle.com> omullarn@oracle.com (Oliver Mullarney) writes: >>procedureX() >>{ char *myString; >> myString = "\pExample string"; >>} >> > >This is just a little dubious; no space is being allocated anywhere, so >this should not be used in a general case. It will work for the given >situation, but not once you drop up one level on the stack from where >the assignment is made (literals are defined on the stack, right?). No, generally speaking, they're allocated in global space. You can give a compiler directive in MPW to make them allocated in code space, though; this is useful mostly in XCMDs and XFCNs. I don't know of any Mac C compilers that put string literals on the stack. Think about the code the compiler would have to generate and you'll see why. Of course, all the discussion here has missed the real point, which is that you almost always should avoid string literals on the Mac (except in XCMDs and XFCNs, where they're considered kosher, because someone moving the XCMD into another stack may forget to move any associated 'STR ' and 'STR#' resources, and they may have to be renumbered to avoid conflicts). Instead, use GetString and GetIndString to get your string constants; this will make it much easier to move your code to other languages. However, in the immortal words of Amanda Walker, if you're making mud pies, it doesn't matter how much sugar you use; if you're just doing a quick and dirty utility or something which you are reasonably sure will always be local to your site, go ahead and use the literals. Finally, the most useful string manipulation utility is BlockMove. Use it often and without compunction. -- Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com FROM THE FOOL FILE: "The negro slaves of the South are the happiest, and, in some sense, the freest people in the world. The children and the aged and infirm work not at all, and yet have all the comforts and neccessaries of life provided for them." -- George Fitzhugh, CANNIBALS ALL! OR, SLAVES WITHOUT MASTERS, 1857