On 2011-04-05, Francois Grieu <> wrote:
> On 05/04/2011 08:06, Peter Nilsson wrote:
>> A strictly conforming program cannot modify the contents of argv[].
> Why ? 5.1.2.2.1p2 says
> " ? The parameters argc and argv and the strings pointed to by the
> argv array shall be modifiable by the program, and retain their
> last-stored values between program startup and program termination."
To be picky:
That is two of the three. The contents of argv is the third.
We are assured that argc and argv themselves are modifiable. The members
of the argv array are not mentioned. The strings *pointed to* by the argv
array are mentioned. So imagine the following setup:
char writeable[] = "foo\0";
const char *first = &writeable[0];
char **argv = { (char *) first, NULL };
main(1, argv);
This complies with the description given in the standard, but if you
try to change argv[0], you invoke undefined behavior.
-s
--
Copyright 2011, all wrongs reversed. Peter Seebach /
usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.