在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