Seebs said:
OK, so that was not a good example.
#include <stdio.h>
int main(int argc, char **argv)
{
const char *argv1 = argc > 1 ? argv[1] : "";
if (argv1 != argv[1]) puts("gotach!");
}
A conforming implementation may print "gotcha"?
I don't know. I wouldn't think so.
So why not? Your interpretation of 5.1.2.2.1 is that it does not apply
to the pointers themselves. I agree (though I think it is an
oversight). That interpretation must also extend to the fact that argv
and the strings pointed to "retain their last-stored values between program
startup and program termination" but the pointers need not. What is the
point of singling out argc, argv and the pointed to strings as holding
their values (and being modifiable) if the pointers in argv are not
being implicitly excluded from that guarantee (as you take them to be as
far as modifiability is concerned)?
I certainly understand your view, but I don't see where it comes from.
What prevents them from changing on their own? If it is some other part
of the standard that gives a blanket assurance about non-volatile
objects, then I don't see why 5.1.2.2.1 needs to say anything about argv
and friends holding their last stored values.
Why are argc, argv and the pointed to strings specifically stated to
hold their last stored values?
The standard doesn't say they're modifiable. And maybe it's an oversight,
rather than a deliberate omission, but:
1. I believe I've used systems where modifying them could have unexpected
results (if not results typically observable from within the program).
2. I don't see much reason to make an assumption either way.
Hmm. Here's the thing. They're things of some sort, and thus, unless
the abstract machine says they change, or they're volatile, their values
are assumed not to change. But that doesn't mean they're modifiable.
Yes, I accept you view about their modifiability. If they are protected
from spontaneous modification by general prohibitions on such changes,
why are argc, argv and the pointed-to strings singled out as holding
their values?
My opinion is that, since argc and friends are the interface between the
program and "the system" they need special mention. We must be told
they are modifiable and that "the system" does not change them behind
our back. My guess is that this statement is intended to apply to the
pointer in argv as well, but if you read one part of special statement
as not applying to the pointers, then I think you have to read the other
part as not applying to them as well. The reason for making this point
is not that I think argv[1] can change spontaneously, but that reading
of 5.1.2.2.1 that prevents its modification has worrying consequences
that suggest there was an oversight rather than a deliberate exclusion.