Why argv[i][j] modifiable?, argv[0] = something, again

Why argv[i][j] modifiable?, argv[0] = something, again

Post by Arthur J. » Fri, 02 Mar 2007 05:19:33



Pardon my ignorance, but *why* is it a good thing to prohibit the
implementation from passing the program arguments as literals?
You seem to be saying that there's a good rationale for requiring
argv[i][j] to be modifiable; what is that rationale?

David Tribble points out that this requirement complicates recursive
calls to 'main'; I imagine it might complicate the startup code on some
implementations, too. So, what's the "good case" that makes all this
complication worthwhile?

-Arthur
(I checked the Rationale, and didn't see anything relevant.)
 
 
 

Why argv[i][j] modifiable?, argv[0] = something, again

Post by Keith Thom » Fri, 02 Mar 2007 05:37:58

"Arthur J. O'Dwyer" < XXXX@XXXXX.COM > writes:

[...]
[...]

Perhaps it's a matter of historical practice. Allowing unmodifiable
literals would have broken pre-ANSI programs that modified their
arguments. Modifying the strings in place isn't necessarily the best
approach, but that gets back to the question of whether the argv[i]
pointers are modifiable.

--
Keith Thompson (The_Other_Keith) XXXX@XXXXX.COM < http://www.yqcomputer.com/ ~kst>
San Diego Supercomputer Center <*> < http://www.yqcomputer.com/ ~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

 
 
 

Why argv[i][j] modifiable?, argv[0] = something, again

Post by richar » Fri, 02 Mar 2007 06:17:27

In article < XXXX@XXXXX.COM >,



Some programs on some unixes modify argv[0][x] to change what is
displayed by programs like "ps" that list the running processes. I
notice that this has that effect on the Mac I am using, but changing
argv[0] itself doesn't.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
 
 
 

Why argv[i][j] modifiable?, argv[0] = something, again

Post by SGFyYWxkIH » Fri, 02 Mar 2007 16:12:41


Programs that accept options in the form of -Xoption=value can store
this as a pair of pointers, one to "option", and one to "value". The
easiest way to handle this is to replace the = by '\0' and point
directly into argv[i]. Some programs do this, probably even before C90.