执行 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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值