Path: utzoo!attcan!uunet!mcvax!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.lang.c Subject: Re: Modifying string literals (was Re: Are strings local?) Keywords: Help! Message-ID: <574@philmds.UUCP> Date: 5 Aug 88 22:03:44 GMT References: <644@m10ux.UUCP> <12791@mimsy.UUCP> <652@m10ux.UUCP> <24986@think.UUCP> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 22 In article <24986@think.UUCP> barmar@kulla.think.com.UUCP (Barry Margolin) writes: >In article <652@m10ux.UUCP> rgr@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?) > >Yes, compilers will allow this, but it is not a good idea, and I >believe that ANSI C specifically says that it is a no-no. A compiler >is permitted to allocate string literals in read-only memory. I think [rest deleted]... Indeed. The VMS C compiler does just this. I believe something like tmpnam("fooXXXXXX"); where tmpnam should fill in the XXXXXX with a (process unique?) id, just stack dumped because it tried to write into readonly memory. Not that I'm suggesting anyone should use VMS or VMS C ........ 8-). Leo.