By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,798 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,798 IT Pros & Developers. It's quick & easy.

Is argv writeable?

P: n/a
Supposed the ith actual argument argv[i] has length n. Am I allowed to
write any string of length <=n to argv[i] ?

Thanks in advance,
Alex.

PS. To email me, remove "loeschedies" from the email address given.
Jul 22 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a

"Alexander Malkis" <al*****************@face.cs.uni-sb.de> wrote in message
news:c8************@hades.rz.uni-saarland.de...
Supposed the ith actual argument argv[i] has length n. Am I allowed to
write any string of length <=n to argv[i] ?

Thanks in advance,
Alex.

PS. To email me, remove "loeschedies" from the email address given.


If I recall, some systems do not even provide facilities for command-line
arguments. On systems that do, I think it's implementation and
system-specific as to how it's implemented.

But since there is no const in those arguments, I imagine it's theoretically
possible to write to those locations. The question is...why? They're not
outputs. Changing them won't change what was on the command line when the
program was invoked.

If you want to hold onto the array and modify its content, then make your
own copies of the strings in appropriate data structures (a vector of string
type seems appropriate), and manipulate those. That way you're sure it will
work (provided of course that you can get those command line arguments in
the first place).

-Howard

Jul 22 '05 #2

P: n/a
Howard wrote:
"Alexander Malkis" <al*****************@face.cs.uni-sb.de> wrote in message
news:c8************@hades.rz.uni-saarland.de...
Supposed the ith actual argument argv[i] has length n. Am I allowed to
write any string of length <=n to argv[i] ?

Thanks in advance,
Alex.

PS. To email me, remove "loeschedies" from the email address given.

If I recall, some systems do not even provide facilities for command-line
arguments. On systems that do, I think it's implementation and
system-specific as to how it's implemented.

But since there is no const in those arguments, I imagine it's theoretically
possible to write to those locations. The question is...why? They're not
outputs. Changing them won't change what was on the command line when the
program was invoked.


On some Unices, changing the contents of argv is a tricky way to change
the output shown by "ps", e.g. to display the progress of a process
instead of just its name. Of course, a more platform-specific hack
there never was...
Jul 22 '05 #3

P: n/a
Howard wrote:
"Alexander Malkis" <al*****************@face.cs.uni-sb.de> wrote in message
news:c8************@hades.rz.uni-saarland.de...
Supposed the ith actual argument argv[i] has length n. Am I allowed to
write any string of length <=n to argv[i] ?

Thanks in advance,
Alex.

PS. To email me, remove "loeschedies" from the email address given.

If I recall, some systems do not even provide facilities for command-line
arguments. On systems that do, I think it's implementation and
system-specific as to how it's implemented.

But since there is no const in those arguments, I imagine it's theoretically
possible to write to those locations. The question is...why? They're not
outputs. Changing them won't change what was on the command line when the
program was invoked.

If you want to hold onto the array and modify its content, then make your
own copies of the strings in appropriate data structures (a vector of string
type seems appropriate), and manipulate those. That way you're sure it will
work (provided of course that you can get those command line arguments in
the first place).


One example is this:

void main ( int argc, char **argv )
{

Widget shell, msg;
XtAppContext app;
XmString xmstr;
shell = XtAppInitialize (&app, "Memo", NULL, 0, &argc, argv, NULL,
NULL, 0 );

This is a standard way to initialize an Xt application where command
line arguments are consumed by the library and the function
XtAppInitialize is expected to remove the argv components it has used
leaving the application specific components for the application to consume.

....

Jul 22 '05 #4

P: n/a
Alexander Malkis wrote:

Supposed the ith actual argument argv[i] has length n. Am I allowed to
write any string of length <=n to argv[i] ?

Yes.


Brian Rodenborn
Jul 22 '05 #5

P: n/a

"Gianni Mariani" <gi*******@mariani.ws> wrote in message
news:c8********@dispatch.concentric.net...
The question is...why?

One example is this:

void main ( int argc, char **argv )
{

Widget shell, msg;
XtAppContext app;
XmString xmstr;
shell = XtAppInitialize (&app, "Memo", NULL, 0, &argc, argv, NULL,
NULL, 0 );

This is a standard way to initialize an Xt application where command
line arguments are consumed by the library and the function
XtAppInitialize is expected to remove the argv components it has used
leaving the application specific components for the application to consume.


Interesting! Looks quite useful.

As I said, the signature sure seems to allow writing to argv. But does the
standard guarantee it?

-Howard


Jul 22 '05 #6

P: n/a
Gianni Mariani <gi*******@mariani.ws> wrote in message news:<c8********@dispatch.concentric.net>...
Howard wrote:
"Alexander Malkis" <al*****************@face.cs.uni-sb.de> wrote in message
news:c8************@hades.rz.uni-saarland.de...
Supposed the ith actual argument argv[i] has length n. Am I allowed to
write any string of length <=n to argv[i] ?

Thanks in advance,
Alex.

PS. To email me, remove "loeschedies" from the email address given.

If I recall, some systems do not even provide facilities for command-line
arguments. On systems that do, I think it's implementation and
system-specific as to how it's implemented.

But since there is no const in those arguments, I imagine it's theoretically
possible to write to those locations. The question is...why? They're not
outputs. Changing them won't change what was on the command line when the
program was invoked.

If you want to hold onto the array and modify its content, then make your
own copies of the strings in appropriate data structures (a vector of string
type seems appropriate), and manipulate those. That way you're sure it will
work (provided of course that you can get those command line arguments in
the first place).


One example is this:

void main ( int argc, char **argv )

^^^^

void(?)

--
Imanpreet Singh Arora
Jul 22 '05 #7

P: n/a

"Howard" <al*****@hotmail.com> wrote in message
news:lV*******************@bgtnsc05-news.ops.worldnet.att.net...

"Gianni Mariani" <gi*******@mariani.ws> wrote in message
news:c8********@dispatch.concentric.net...
The question is...why?

One example is this:

void main ( int argc, char **argv )
{

Widget shell, msg;
XtAppContext app;
XmString xmstr;
shell = XtAppInitialize (&app, "Memo", NULL, 0, &argc, argv, NULL,
NULL, 0 );

This is a standard way to initialize an Xt application where command
line arguments are consumed by the library and the function
XtAppInitialize is expected to remove the argv components it has used
leaving the application specific components for the application to

consume.


Interesting! Looks quite useful.

As I said, the signature sure seems to allow writing to argv. But does

the standard guarantee it?


The C (99) standard does explicitly make this gurantee, but
I don't see it in the C++(98) standard. (Or maybe I'm looking
in the wrong place ... wouldn't be the first time. :-) )

-Mike
Jul 22 '05 #8

P: n/a
Mike Wahler wrote:
The C (99) standard does explicitly make this gurantee, but
I don't see it in the C++(98) standard. (Or maybe I'm looking
in the wrong place ... wouldn't be the first time. :-) )


As did the C89 standard before it. I wonder why they left out that bit
of boilerplate, if it's missing from the final standard (I just have the
last draft).

The C standard says:

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.

Brian Rodenborn
Jul 22 '05 #9

P: n/a

"Default User" <fi********@boeing.com.invalid> wrote in message
news:40***************@boeing.com.invalid...
Mike Wahler wrote:
The C (99) standard does explicitly make this gurantee, but
I don't see it in the C++(98) standard. (Or maybe I'm looking
in the wrong place ... wouldn't be the first time. :-) )


As did the C89 standard before it. I wonder why they left out that bit
of boilerplate, if it's missing from the final standard (I just have the
last draft).

The C standard says:

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.


Yes, I found that, but no similar wording in the C++ standard.

-Mike
Jul 22 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.