pcc shared string question

greg at sdcsvax.UUCP greg at sdcsvax.UUCP
Fri Jul 27 04:37:36 AEST 1984


In article <106 at msdc.UUCP> dan at msdc.UUCP (Dan Forsyth) writes:
>None of the libraries ever modify double-quoted literals ....  So,
>what kind of trouble am I buying here?  What have I missed?

Close.  The original implementation of our compiler put double-quoted
strings in text space and we got along just fine for months.  However,
although nowhere in the LIBRARIES are double-quoted literals modified,
at least one UTILITY does.  The offending utility is "ed" which has:
    tfname = mktemp("/tmp/eXXXXXX");
in it.  Mktemp() blissfully stomps on the string passed to it, so this
will modify the literal.  I'd argue that this is bad coding practice,
but in the end, we put our strings in the data segment to be compatible
with the rest of the C community.  (My feeling is that literals should
be literal (i.e., mean what they say) and thus should NOT be modifyable.)

Other than dangers like that, you should be perfectly safe in putting
your strings in the text area.  I'd be curious to know if you encounter
any other problems.

Does anybody know what the proposed C standard has to say on the subject?
I'd be willing to propose that literals (as opposed to initializers) be
read-only by default, as if they had the "const" attribute.  Anybody have
any other thoughts on the subject?
-- 
-- Greg Noel, NCR Torrey Pines       Greg at sdcsvax.UUCP or Greg at nosc.ARPA



More information about the Comp.unix.wizards mailing list