473,385 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Is argv writeable?

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
9 1762

"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
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
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
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

"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
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

"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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Robin Sanderson | last post by:
Sorry in advance if this is a stupid question - I am new to C++. In the process of converting program to be run from the command line into a function to be run from another program I noticed...
28
by: Charles Sullivan | last post by:
I'm working on a program which has a "tree" of command line arguments, i.e., myprogram level1 ]] such that there can be more than one level2 argument for each level1 argument and more than one...
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
1
by: lawrence k | last post by:
I'm trying to write some RSS feeds. I've created a folder called rss, and it lives in the same directory as my scripts. I run the script and get no result. I put in a is_writeable() check and it...
22
by: Joe Smith | last post by:
It is nothing short of embarrassing to feel the need to ask for help on this. I can't see how I would make the main control for this. What I want is a for loop and a test condition. And while I...
1
by: Marco Shaw | last post by:
Is there something built-in to .net to determine if a directory is writeable by the current user? I want to write a Windows Powershell script that needs to write to a directory. I can certainly...
4
by: interec | last post by:
Hi Folks, I am writing a c++ program on redhat linux using main(int argc, wchar_t *argv). $LANG on console is set to "en_US.UTF-8". g++ compiler version is 3.4.6. Q1. what is the encoding of...
1
by: jaleel | last post by:
In a windows application I have an xml file which is readable and writeable. I wnat to ensure that this file is writeable if it is set to read-only. I am doing my work using the code: ...
3
by: Tim Kelley | last post by:
Is there a way to determine if a CD/DVD is writeable? I have looked at using WMI (Win32_CDROMDrive) but it did not have any luck. Thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.