本文介绍了如何在没有警告的情况下使用execv()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用GCC 4.2的MacOS-X Lion。这段代码有效,但我收到了一个警告,我想修复:
#include< unistd.h>
main()
{
char * args [] = {/ bin / ls,-r,-t,-l,(char *)0 };
execv(/ bin / ls,args);
}
我不希望警告被压制,我不想拥有它。
它是C ++代码,而不是C。使用char * const(所以execv()所需的类型仍然会产生警告。) p>
谢谢。
解决方案
这似乎很好:
#include< unistd.h>
main()
{
char const * args [] = {/ bin / ls,-r,-t,-l,NULL};
execv(/ bin / ls,const_cast< char **>(args));
}
I am working on MacOS-X Lion with GCC 4.2. This code works, but I get a warning I would like fix:
#include <unistd.h>
main()
{
char *args[] = {"/bin/ls", "-r", "-t", "-l", (char *) 0 };
execv("/bin/ls", args);
}
I do not want the warning to be suppressed, I want not to have it at all.It is C++ code, not C.
Using a char *const (so exactly the type required by execv()) still produces the warning.
Thank you.
解决方案
This seems to be ok:
#include <unistd.h>
main()
{
char const *args[] = {"/bin/ls", "-r", "-t", "-l", NULL };
execv("/bin/ls", const_cast<char**>(args));
}
这篇关于如何在没有警告的情况下使用execv()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!