String help!

Henry Spencer henry at utzoo.UUCP
Tue Mar 5 07:05:42 AEST 1985


> > In DEC C, string constants are read-only.  They are in a special, write-
> > protected psect.  If you try to do something like the above, you will
> > get a run-time error.  --  Jeff Lichtman
> 
> What does the standard say about this?  Can an implementation legally prevent
> a C program from modifying storage accessed by a valid pointer?

The latest ANSI draft (11 Feb 1985) says that string literals are of
type "const char[]" (not just "char[]") and thus it is illegal for you
to alter their contents.  This has both advantages and disadvantages.
It will break some programs, notably ones that use mktemp() in the
most simplistic way.  On the other hand, it will produce widespread
(if modest) improvements in efficiency, and will make life noticeably
easier for people writing C code to go in ROM.  [Please, let us not
have a renewed debate on the merits or lack thereof of this change;
we did that, at length, a few months ago.]
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry



More information about the Comp.lang.c mailing list