在linux下用gcc编译下面的代码
#include <unistd.h>
int main()
{
execl("/bin/echo", "echo", "hello,world", 0);
}
会报出警告: warning: missing sentinel in function call[-Wformat]
查看execl的manual,里面说execl函数要用char*型的NULL作结束符,0是int型,所以会报出警告。
execl的manual原文:
SYNOPSIS
int execl(const char *path, const char*arg, ...);
DESCRIPTION
...The list of arguments must beterminated by a NULL pointer, and, since these are variadicfunctions, this pointer must be cast (char *) NULL.
将代码修改成
execl("/bin/echo", "echo","hello,world", NULL);
或者
execl("/bin/echo", "echo","hello,world", (char*)0);
警告消失。
参考:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33403
http://blog.csdn.net/candcplusplus/article/details/8229330