Re: code question
Richard Heathfield <rjh@see.sig.in validwrites:
[...]
[...]
argv[0] is also allowed to point to an empty string if the program
name is not available. The standard's exact wording (C99 5.1.2.2.1p2)
is:
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.
But the requirement that the string pointed to by argv[0][0]
"represents the program name" is largely unenforced and unenforceable.
Under POSIX, for example, the string is whatever the invoking program
wants it to be. Though I suppose you could define "program name" in
such a way as to make this consistent. In fact, since "program name"
is in italics in the quoted paragraph, that supposedly *is* the
definition of the phrase -- though I'm not convinced it's really a
definition at all. It would make as much sense, and be more
consistent, for the standard to say that the string *is* the program
name.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Richard Heathfield <rjh@see.sig.in validwrites:
[...]
argv[0] is guaranteed *either* to represent the program name or to be NULL
(and argc to be 0), and the scanning sequence works fine whichever of
these is the case.
(and argc to be 0), and the scanning sequence works fine whichever of
these is the case.
argv[0] is also allowed to point to an empty string if the program
name is not available. The standard's exact wording (C99 5.1.2.2.1p2)
is:
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.
But the requirement that the string pointed to by argv[0][0]
"represents the program name" is largely unenforced and unenforceable.
Under POSIX, for example, the string is whatever the invoking program
wants it to be. Though I suppose you could define "program name" in
such a way as to make this consistent. In fact, since "program name"
is in italics in the quoted paragraph, that supposedly *is* the
definition of the phrase -- though I'm not convinced it's really a
definition at all. It would make as much sense, and be more
consistent, for the standard to say that the string *is* the program
name.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Comment