Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/3/84; site talcott.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!kendall From: kendall@talcott.UUCP (Sam Kendall) Newsgroups: net.lang.c Subject: Re: Re: String help! (getting ANSI C strings back out of ROM) Message-ID: <375@talcott.UUCP> Date: Thu, 21-Mar-85 19:19:20 EST Article-I.D.: talcott.375 Posted: Thu Mar 21 19:19:20 1985 Date-Received: Sat, 23-Mar-85 01:21:13 EST References: <1156@ukma.UUCP> <113@mit-athena.UUCP> <573@rlgvax.UUCP> <2181@pegasus.UUCP> Organization: Sociology Dept., Harvard Univ. Lines: 22 > mktemp ("/tmp/fooXXXXXX"); > > becomes > > mktemp ( (char *) "/tmp/fooXXXXXX"); > > Since the cast is used withOUT the "const" qualifier, the compiler is forced > to place the string in writable memory. Note that I am NOT casting a "char *" > back into a "char *", but am instead casting a "const char *" into a "char *". > > Tony Hansen > pegasus!hansen This won't do it. The cast makes a pointer to non-const out of a pointer to const, but the result of the cast still points to storage defined as const, so the result of any attempt to modify it (by mktemp) is undefined. See Guy Harris's note on this topic for the right way to do it. Sam Kendall Delft Consulting {allegra, ihnp4}!pyuxvv!delftcc!sam