Liste des Groupes | Revenir à cl c |
On 8/2/24 5:43 AM, Bart wrote:My post wasn't about numerical literals. I assumed it was about that '1' value which is stored B's first cell.On 02/08/2024 02:06, Kaz Kylheku wrote:You don't get a choice in the matter. The C language doesn't permitOn 2024-08-01, Bart <bc@freeuk.com> wrote:>>>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:
static char A[100];
static char B[100]={1};
>
Do these not also have static storage duration? Yet presumably these can
be legally modified.
That 1 which initializes B[0] cannot be modified.
>
Why not? I haven't requested that those are 'const'. ...
numeric literals of any kind to be modified by your code.
and don't need to be, declared 'const'. I've heard that in some otherIt can't modified, in a value that would also affect other instances of '1' within that module or produce, because it is very unlikely to be shared.
languages, if you call foo(3), and foo() changes the value of it's
argument to 2, then subsequent calls to bar(3) will pass a value of 2 to
bar(). That sounds like such a ridiculous mis-feature that I hesitate to
identify which languages I had heard accused of having that feature, but
it is important to note that C is not one of them.
Just as 1 is an integer literal whose value cannot be modified,
Les messages affichés proviennent d'usenet.