修改argv指向的字符串 [英] modifying the strings pointed to by argv

查看:86
本文介绍了修改argv指向的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准允许我们可以将字符串复制到arg [0],arg [1]等。

为什么允许?

最大值是多少复制的这种字符串的长度?

The standard allows that we can copy strings onto arg[0], arg[1], etc.
Why is it allowed ?
What can be the maximum length of such a string that is copied ?

推荐答案

su ************** @ yahoo.com ,印度说:
su**************@yahoo.com, India said:

标准允许我们将字符串复制到arg [0],arg [1]等。

为什么允许它?
The standard allows that we can copy strings onto arg[0], arg[1], etc.
Why is it allowed ?



好​​问题。为什么呢?这是一个愚蠢的愚蠢想法,如果有的话,那么就有一个。

Good question. Why indeed? It''s a stupid stupid stupid idea, if ever
there was one.


这样一个字符串的最大长度是多少被复制?
What can be the maximum length of such a string that is copied ?



0,如果你有很多意义。如果您只有一点意义,那么找出现有字符串的长度,并且不要超过该值。如果

您没有任何意义,请不要理会上述

建议之一。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名, - www。

0, if you have lots of sense. If you have only a little sense, then find
out how long the existing string is, and don''t exceed that value. If
you have no sense whatsoever, pay no attention to either of the above
suggestions.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


3月14日,13:19,Richard Heathfield< r ... @ see.sig.invalidwrote:
On 14 Mar, 13:19, Richard Heathfield <r...@see.sig.invalidwrote:

subramanian10 ... @ yahoo.com,India说:
subramanian10...@yahoo.com, India said:

标准允许我们将字符串复制到arg [0],arg [1]等。

为什么允许它?
The standard allows that we can copy strings onto arg[0], arg[1], etc.
Why is it allowed ?



好​​问题。为什么呢?这是一个愚蠢的愚蠢想法,如果有的话,那就是b $ b。


Good question. Why indeed? It''s a stupid stupid stupid idea, if ever
there was one.



好​​吧,可能,但是没有特别好的理由我可以看到

传递给你的函数的参数被读取-只要。它可能对于空间修剪或类似的输入参数很有用。

肯定有至少一个(不可否认的次优)unix [1] hack

涉及修改argv []值,以便程序参数不会出现在ps进程列表中的



你能不能澄清为什么你认为这个功能是不明智的?

[1]当然,稍微偏离主题这里,但是再次有一个很好的

C中的一些东西标准是那种避免打破代码如何工作的方式,所以我想为这次讨论申请一个临时的主题

许可证。 />

Well, possibly, but there''s no particularly good reason I can see for
the arguments passed to your function to be read-only. It could
potentially be useful to space-trim or similar the input arguments and
certainly there''s at least one (admittedly sub-optimal) unix[1] hack
involving modifying the argv[] values so that program arguments do not
appear in the ps process listing.

Can you clear up why you think this functionality is unwise ?
[1] Granted, slightly off-topic here, but then again there''s a good
few things in the C standard that are that way to avoid breaking how
existng code works, so I''d like to apply for a temporary on-topic
licence for this discussion.



3月14日9:09?* pm,subramanian10 ... @ yahoo.com,India

< subramanian10 ... @ yahoo.comwrote:
On Mar 14, 9:09?*pm, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.comwrote:

标准允许我们将字符串复制到arg [0],arg [1]等。

为什么允许?

什么可以复制的这种字符串的最大长度是多少?
The standard allows that we can copy strings onto arg[0], arg[1], etc.
Why is it allowed ?
What can be the maximum length of such a string that is copied ?



好​​吧。还有一些事情需要澄清。


标准只是说argc和argv以及

指向的字符串argv数组应该是modi吗? 能够通过该计划。但argv数组

_itself_是_not_必须是modi ???.


以下错误代码只适用于argc> = 2和

strlen(argv [1])> = 1:


#include< stdio.h>

#include < string.h>


int main(int argc,char * argv [])

{

char buf [ 2] = {0};

strcpy(argv [1],buf);

返回0;

}


我猜这个可修改的可以考虑用于exec *()函数

或者main()的递归。最大长度可以在

POSIX中找到。

Well. There is still something to be clarify.

The standard just says "argc and argv and the strings pointed to by
the argv array shall be modi???able by the program." But the argv array
_itself_ is _not_ required to be modi???able.

The following buggy code only works well when argc >=2 and
strlen(argv[1]) >=1:

#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
char buf[2] = {0};
strcpy(argv[1], buf);
return 0;
}

I guess making that modifiable may be considered for exec*() functions
or for the recursion of main(). And the maximum length maybe found in
POSIX.


这篇关于修改argv指向的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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