| Deutsch English Français Italiano |
|
<87frrogdhg.fsf@nosuchdomain.example.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.misty.com!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: relearning C: why does an in-place change to a char* segfault?
Date: Thu, 01 Aug 2024 14:06:03 -0700
Organization: None to speak of
Lines: 27
Message-ID: <87frrogdhg.fsf@nosuchdomain.example.com>
References: <IoGcndcJ1Zm83zb7nZ2dnZfqnPWdnZ2d@brightview.co.uk>
<20240801114615.906@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Thu, 01 Aug 2024 23:06:04 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="933b865835dd2da7485caeddca825875";
logging-data="2515784"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/RgFAfedvZqPsFPbw5+FLL"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:nUYqCNRdRuikFUi3mbCQm5cXJtU=
sha1:d0VfGuJomVKEiwzUqfGY4nvrj3k=
Bytes: 2132
Kaz Kylheku <643-408-1753@kylheku.com> writes:
> On 2024-08-01, Mark Summerfield <mark@qtrac.eu> wrote:
[...]
>> int main() {
>> char* text = "this is a test";
>
> The "this is a test" object is a literal. It is part of the program's image.
> When you try to change it, you're making your program self-modifying.
The ISO C language standard doesn't require the object to be part of the
program's image. A fully conforming implementation could store it in
read/write memory and allow it to be modified. Or, it could store it in
some kind of storage where attempts to write to it appear to succeed,
but do not actually modify it (this is implausible, but allowed by the
standard).
> The ISO C language standard doesn't require implementations to support
> self-modifying programs; the behavior is left undefined.
The behavior is undefined because the standard explicitly says so.
There is no reference to self-modifying programs.
[...]
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */