Ben Bacarisse said:
Seebs said:
My thoughts are:
1. Unless otherwise specified, everything retains its last stored value.
2. Unless otherwise specified, are not necessarily modifiable.
3. It is not a violation of any rule for the standard to occasionally
specify something which was implicit in other information already
available.
OK. Let's agree to differ. I find extra statements (especially when
they have an implicit omission) highly suggestive but I agree there is
no rule against them.
I think that the statement that the contents of the strings retain their
last stored values is probably harmless but not necessary -- I think it
would have to be true anyway.
Not so. They're not qualified-volatile, therefore, they must not change
WHETHER OR NOT there's a restatement of that in this section.
I am not 100% sure that this is a simple restatement. The reason is
that volatile-qualified objects *also* hold their last-stored value
throughout their lifetime -- it is just that the last store may be
external to the program. 6.2.4 is quote clear about that. The wording
in question seems to be saying something new that is not directly
related to volatile objects. I.e. it does not need to be said about any
object -- volatile or not and that makes me less sure that it can simply
be regarded as restating the obvious.
If you took out the claim that the contents of the strings don't change,
I don't think the meaning of the spec would change.
I won't keep baning on about this. I am not sure we are getting any
further and, in truth, does either of us care? My lingering curiosity
is now as to why you read a sentence that excludes argv[x] from the two
properties it imparts to argv and to argv[x][y] as if one of the two
properties need not be mentioned at all.
Because the standard has an explicit statement elsewhere that objects
retain their last stored values, with some exceptions. This was never
identified as an exception. So it didn't need to be mentioned at all.
However, there's no general rule that all things you can have
pointers to are modifiable. String literals give us a nice example
of something that's not declared const, but which is not modifiable.
This would be a more persuasive line if it were not for that fact that
all the (other) situations where an object isn't modifiable seem to be
very explicitly stated. I suspect that the non-modifiablity of argv[0]
though argv[argc-1] will turn out to be the only one that is not
explicit.
I realize I'm late to the party here, but I thought I'd throw my
two cents in.
I agree with the conclusion that the pointers in the argv array
keep their original values, but not using the same reasoning. Look
at the language of 5.1.2.2.1p2 item 3:
If the value of argc is greater than zero, the array members
argv[0] through argv[argc-1] inclusive shall contain
pointers to strings, which are given ...
What it says is that the array members shall contain pointers to
strings (and not just any strings, but the strings identified by the
subsequent "which" clause); not just that they do when the program
starts, but that they do. Since there is no time qualification, the
stated restrictions should apply throughout program execution, ie,
the array values are unchanging.
Furthermore, note the language in subsequent items of 5.1.2.2.1p2:
If the value of argc is greater than zero, the string
pointed to by argv[0] represents the program name;
argv[0][0] shall be the null character if the program name
is not available from the host environment. If the value of
argc is greater than one, the strings pointed to by argv[1]
through argv[argc-1] represent the program parameters.
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.
Use of the phrase "the strings" in these items implicitly carry a
statement that the pointers to these strings, ie, the array values,
are unchanging; otherwise the language would have been "whatever
strings pointed to by" or "any strings pointed to by" or something
similar. Clearly whoever wrote the paragraph is expecting that
the values in the argv array point to the same strings throughout
execution.
Finally, note that 5.1.2.2.1p2 item 3 contains a "shall" requirement.
By 4p2, if this requirement is violated, the behavior is undefined.
The wording of 5.1.2.2.1p2 item 3 seems clear enough that the strings
in question are those given "implementation-defined values by the
host environment". Any change to an element of the argv array would
violate the stated requirement, resulting in undefined behavior.