Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ukma.UUCP Path: utzoo!watmath!clyde!cbosgd!ukma!david From: david@ukma.UUCP (David Herron, NPR Lover) Newsgroups: net.lang.c Subject: Re: String help! Message-ID: <1156@ukma.UUCP> Date: Tue, 5-Mar-85 22:07:11 EST Article-I.D.: ukma.1156 Posted: Tue Mar 5 22:07:11 1985 Date-Received: Thu, 7-Mar-85 03:49:00 EST References: <7027@watdaisy.UUCP> <8257@watarts.UUCP> <929@ukma.UUCP> <437@ark.UUCP> <194@rtech.ARPA> Organization: Univ. of KY Mathematical Sciences Lines: 39 >> > main() >> > { >> > char *ptr; >> > char *foo(); >> > >> > ptr = foo(); >> > strcpy( ptr, "barfoo" ); >> > ..... >> > } >> >> 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? A string constant (like above) is a CONSTANT. You should be prevented from changing the values of CONSTANTS. The fact that you ever could is laziness (or something) on the part of the original implementors. Allowing one to change the value of constants (can, not necessarily will) create hard to find bugs. (usually in the case of careless programmers...) What I want to know is what (of the code above) would generate a run-time error? -- :------------------------------------------------------------------: :- David Herron -: :- -: :- ARPA-> "ukma!david"@ANL-MCS or david%ukma.uucp@anl-mcs.arpa -: :- ARPA-> Or even anlams!ukma!david@ucbvax.arpa -: :- -: :- UUCP-> {ucbvax,unmvax,boulder,research}!anlams!ukma!david -: :- UUCP-> {mcvax!qtlon,vax135,mddc}!qusavx!ukma!david -: :- UUCP-> {A-Large-Portion-of-The-World}!cbosgd!ukma!david -: :------------------------------------------------------------------: "The home of poly-unsaturated thinking".