my two cents

Joe Buck jbuck at epimass.EPI.COM
Tue Aug 9 02:26:01 AEST 1988


In article <5812 at batcomputer.tn.cornell.edu> davidra at batcomputer.tn.cornell.edu (David A. Rabson) writes:
>I just got my hands on a copy of the second edition of K&R and was
>distressed to read that "[string constants] are no longer modifiable,
>and so may be placed in read-only memory."
>This will cause mktemp() and many, many other things to break.

It only causes certain uses of mktemp to break.  You can no longer say

	name = mktemp ("/tmp/fileXXXXXX");

but you can say

	char template[] = "/tmp/fileXXXXXX", *name;
	name = mktemp (template);

I know of no other code I've ever written that this change would break.
But then, I do a lot of C code for standalone applications (C in ROM,
with a minimal real-time OS) and in the compiler I use for that, strings
go in a separate section and I put that section in ROM.

There's also the Berkeley xstr hack, for collecting commonly used strings
and compressing.  This will only work if you don't attempt to modify strings.
-- 
- Joe Buck  {uunet,ucbvax,pyramid,<smart-site>}!epimass.epi.com!jbuck
jbuck at epimass.epi.com	Old Arpa mailers: jbuck%epimass.epi.com at uunet.uu.net
	If you leave your fate in the hands of the gods, don't be 
	surprised if they have a few grins at your expense.	- Tom Robbins



More information about the Comp.std.c mailing list