String help!
David Herron, NPR Lover
david at ukma.UUCP
Wed Mar 6 13:07:11 AEST 1985
>> > 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 at anl-mcs.arpa -:
:- ARPA-> Or even anlams!ukma!david at 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".
More information about the Comp.lang.c
mailing list