執行 execl時發生warning: missing sentinel in function call [-Wformat]警告

linux下用gcc編譯下面的代碼

#include <unistd.h>

int main()
{
	execl("/bin/echo", "echo", "hello,world", 0);
}

會報出警告: warning: missing sentinel in function call[-Wformat]


查看execlmanual,裏面說execl函數要用char*型的NULL作結束符,0int型,所以會報出警告。

execlmanual原文:


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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章