CoL said:
In what case? Quote context please. To quote from one of the MANY posts
where this problem and the solution has been stated:
| "If you want to post a followup via groups.google.com, don't use
| the broken "Reply" link at the bottom of the article. Click on "show
| options" at the top of the article, then click on the "Reply" at the
| bottom of the article headers." - Keith Thompson
|
| Your post needs to be able to stand on its own, you shouldn't assume
| that everyone just finished reading the post you are replying to
| before reading yours. Usenet is not an incredibly reliable medium and
| it is often the case that followups, such as yours, make it to a news
| server before the post you are responding to. It is also not rare for
| news readers to screw up the order of posts and followups, Google
| Groups has a number of problems in this area. If you include context,
| these things become non-issues.
> according to ANSI C standard the string literal becomes
the part of read only memory,
Not quite, none of the ANSI or ISO C standard require read only memory.
> most obvious the datasection. So the
nature of the char * str actually becomes const char *str1... so you
cant write into it.
I'm not sure exactly what you are trying to say, and so I suspect you
have not quite understood the situation.
int main(void)
{
char *ptr="string literal";
*ptr=0;
}
Is syntactically perfectly legal and no compiler is *required* to
complain about it. However, since the standard states that attempting to
modify a string literal is undefined behaviour *anything* can happen if
you run it. The most common things are the program crashing (if the
compiler chooses to place "string literal" in read only memory) andall
string literals ending in "string literal" including the one that says
"This is a string leteral" being affected.
So you are correct if you think that a program is "not allowed" to
modify a string literal, but not if you thing the compiler is required
to complain or if you think the program is guaranteed to crash in a
visible way.