argv可写吗? [英] Is argv writeable?

查看:51
本文介绍了argv可写吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设第i个实际参数argv [i]的长度为n。我允许

写任何字符串长度< = n到argv [i]?


提前谢谢,

Alex。


PS。要给我发电子邮件,请删除loeschedies。从给出的电子邮件地址。

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.

推荐答案



" Alexander Malkis" <人***************** @ face.cs.uni-sb.de>在消息中写道

news:c8 ************ @ hades.rz.uni-saarland.de ...

"Alexander Malkis" <al*****************@face.cs.uni-sb.de> wrote in message
news:c8************@hades.rz.uni-saarland.de...
假设第i实际参数argv [i]的长度为n。我是否允许
写任何字符串长度< = n到argv [i]?

提前致谢,
Alex。

PS 。要给我发电子邮件,请删除loeschedies。从给出的电子邮件地址。
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.




如果我记得,有些系统甚至不提供命令行

参数的设施。在这样的系统上,我认为它的实现和

系统特定于它是如何实现的。


但是因为没有这些论点中的const,我认为理论上可以写入这些位置的b $ b。问题是......为什么?他们不是b
输出。当调用

程序时,更改它们不会改变命令行上的内容。


如果你想保持阵列并修改它内容,然后在适当的数据结构(字符串向量

类型的矢量似乎合适)中使你的

自己的字符串副本,并操纵它们。这样你确定它将会工作(当然,你可以在

中获得这些命令行参数)。


-Howard



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


Howard写道:
" Alexander Malkis" <人***************** @ face.cs.uni-sb.de>在消息中写道
新闻:c8 ************ @ hades.rz.uni-saarland.de ...
"Alexander Malkis" <al*****************@face.cs.uni-sb.de> wrote in message
news:c8************@hades.rz.uni-saarland.de...
假设第i实际参数argv [i]的长度为n。我是否允许
写任何字符串长度< = n到argv [i]?

提前致谢,
Alex。

PS 。要给我发电子邮件,请删除loeschedies。从给出的电子邮件地址。
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.



如果我记得,有些系统甚至不提供命令行
参数的设施。在这样的系统上,我认为它的实现和系统特定于它是如何实现的。

但是由于这些参数中没有const,我想它从理论上讲,可以写入这些地点。问题是......为什么?他们不是产出。当调用
程序时,更改它们不会改变命令行上的内容。


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.




在某些Unices上,更改argv的内容是一个一种棘手的改变方式

输出显示为ps,例如显示进程的进度

而不仅仅是其名称。当然,更具平台性的黑客

从来没有...



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


Howard写道:
" ;亚历山大·马尔基斯(Alexander Malkis) <人***************** @ face.cs.uni-sb.de>在消息中写道
新闻:c8 ************ @ hades.rz.uni-saarland.de ...
"Alexander Malkis" <al*****************@face.cs.uni-sb.de> wrote in message
news:c8************@hades.rz.uni-saarland.de...
假设第i实际参数argv [i]的长度为n。我是否允许
写任何字符串长度< = n到argv [i]?

提前致谢,
Alex。

PS 。要给我发电子邮件,请删除loeschedies。从给出的电子邮件地址。
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.



如果我记得,有些系统甚至不提供命令行
参数的设施。在这样的系统上,我认为它的实现和系统特定于它是如何实现的。

但是由于这些参数中没有const,我想它从理论上讲,可以写入这些地点。问题是......为什么?他们不是产出。当调用
程序时,更改它们不会改变命令行上的内容。

如果你想保持阵列并修改其内容,那么就让你的在适当的数据结构中拥有字符串的副本(字符串
类型的矢量似乎合适),并操纵它们。这样你确定它会工作(前提是你首先可以在
中获得那些命令行参数)。


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).




一个例子是:


void main(int argc,char ** argv)

{


Widget shell,msg;

XtAppContext app;

XmString xmstr;

shell = XtAppInitialize(& app," Memo",NULL ,0,& argc,argv,NULL,

NULL,0);


这是初始化Xt应用程序的标准方法,其中命令为

行参数由库和函数消耗

XtAppInitialize应该删除它已经使用的argv组件

留下特定于应用程序的组件申请消费。


....



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.

....


这篇关于argv可写吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆