为什么ARGV参数execvp不是const的? [英] Why is argv parameter to execvp not const?
问题描述
execvp是这样定义:
execvp is defined thus:
int execvp(const char *file, char *const argv[]);
从正在使用precludes code像这样的:
Which precludes code such as this from being used:
const char* argv[] = {"/bin/my", "command", "here", NULL};
execvp(argv[0], argv);
这是一个意外遗漏?它是安全的const_cast会解决此问题?或者做一些execvp实现实际上是在内存潦草?
Was this an accidental omission? Is it safe to const_cast around this? Or do some execvp implementations actually scribble on that memory?
推荐答案
的POSIX规范说(的 http://pubs.opengroup.org/onlinepubs/009604499/functions/exec.html ):
The POSIX spec says (http://pubs.opengroup.org/onlinepubs/009604499/functions/exec.html):
的的argv []
和 envp []
指针数组和字符串到这些阵列点不应通过调用进行修改的Exec功能之一,除了更换处理图像的结果。
The
argv[]
andenvp[]
arrays of pointers and the strings to which those arrays point shall not be modified by a call to one of the exec functions, except as a consequence of replacing the process image.
<击>我觉得缺失(或错位)常量
只是一个历史怪胎。击>
I think the missing (or misplaced) const
is simply an historical oddity.
这篇关于为什么ARGV参数execvp不是const的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!