Liste des Groupes | Revenir à cl c |
On 2024-08-01, Bart <bc@freeuk.com> wrote:Why not? I haven't requested that those are 'const'. Further, gcc has no problem running this program:Programming languages can have objects that have the same lifetime, yet some>It segfaults when the string is stored in a read-only part of the binary.>
A string literal creates an array object with static storage duration.
Any attempt to modify that array object has undefined behavior.
What's the difference between such an object, and an array like one of
these:
of which are mutable and some of which are immutable.
If the compiler believes that the immutable objects are in fact
not mutated, it's a bad idea to modify them behind the compiler's
back.
There doesn't have to be any actual difference in the implementation of
these objects, like in what area they are stored, other than the rules
regarding their correct use, namely prohibiting modification.
The Racket language has both mutable and immutable cons cells.
The difference is that the immutable cons cells simply lack the
operations needed to mutate them. I'm not an expert on the Racket
internals but I don't see a reason why they couldn't be stored in the
same heap.
static char A[100];That 1 which initializes B[0] cannot be modified.
static char B[100]={1};
>
Do these not also have static storage duration? Yet presumably these can
be legally modified.
Les messages affichés proviennent d'usenet.