B
Ben Bacarisse
Richard Heathfield said:Ben Bacarisse said:
What, even in comp.lang.c?
Yes, I think so.
The case is (quite reasonably) that since "argv[argc] shall be null
a pointer" (5.1.2.2.1p2) argv can't, itself, be == NULL. Let's
reason unreasonably for while...
The evaluation of argv is undefined when argv == NULL, so what
prevents the DS9000's C implementation from defining NULL == NULL
for all i? This will make argv[argc] == NULL even when argv ==
NULL.
That's a circular argument, because it presupposes that argv is
allowed to be a null pointer.
Which is an excellent presupposition unless there is some reason to
think that it can't be so. For example, I assume that argc can be
negative right up to the point where the standard says that it
non-negative. Similarly, there is no reason to imagine argv is
constrained other than by some restriction placed on it by the
standard. That argv[argc] shall be a null pointer is not (to me)
quite enough.
The circular argument would be to assume that it can't be null,
surely? That would be to assume the conclusion. The only way to
proceed is to see if argv == NULL is prevented by some part of the
standard.
Note, too, the text "the strings pointed to by the argv array shall be
modifiable by the program". The wording is sloppy, but we know it
means the strings pointed to by the members of the array to whose
first element argv points. We can easily accept that the number of
strings in that array may be 0 (because argc can be 0 and argv[argc]
must be a null pointer), but it seems to me that the argv pointer
must at least point at that array - and therefore it can't be null.
I would buy this except for the problematic wording. If it said "the
array pointed to by argv" the case would be closed because a null
pointer can't point to an array. Since argv is not an array, that
clause can't say anything about it at all. argv /usually/ points to
an array and, when it does, I suppose we can take your meaning for
that clause, but to reply on it alone seems rather thin.
To be clear: there are two ways to correct the loose wording. One is
to make it say what I think we both agree is meant: "the strings
pointed to by the elements of the array pointed to by argv"; but there
are lots of other possible corrections "if argv points to an array,
both the pointers in that array and the strings pointed to by its
elements are modifiable".
Note that in this later case I chose to clarify something else. The
loose wording is vague about exactly what can be modified. It seems
to permit setting argv and, if argv[0] points to a string, setting
argv[0][0] but it is not clear if argv[0] itself can be assigned to
(when it exists).