在 C++11 中缺少对执行执行的"missing sentinel"警告
Missing "missing sentinel" warning for exec in C++11
如果您忘记在对exec(3)函数之一的调用结束时包含NULL sentinel,GCC将向您发出有用的警告:
#include <unistd.h>
int main(int argc, char **argv)
{
execlp("test", "test", "arg1");
}
GCC 4.8的示例编译器输出:
$ g++ test.cc -Wformat
test.cc: In function ‘int main(int, char**)’:
test.cc:4:32: warning: missing sentinel in function call [-Wformat=]
execlp("test", "test", "arg1");
^
$
但是,如果您在C++11模式下编译,则不会打印诊断:
$ g++ test.cc -std=c++11 -Wformat
$
为什么C++11中没有此警告?有办法把它拿回来吗?
execlp
不是标准的C函数。为了让编译器将其识别为"标准"函数,它知道参数应该是什么样子,需要-std=gnu++11
而不是-std=c++11
。请注意,默认值为-std=gnu++98
。Glibc可以通过在execlp
的声明中指定sentinel
属性来改善这种情况。
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- C++,系统无法执行指定的程序
- 使用C++中的模板和运算符重载执行矩阵运算
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 执行函数时导致崩溃的变量
- 无论条件是否为true,if总是在c++中执行
- 当函数模板参数是具有默认参数的类模板时,函数模板参数的推导如何执行
- 在C++中对T*类型执行std::move的意外行为
- 使用QProcess执行命令,并将结果存储在QStringList中
- 如何在没有信号的情况下从C++执行QML插槽
- 如何确认我的constexpr表达式实际上已经在编译时执行
- C++17中的并行执行策略
- QML按钮点击功能执行顺序
- 程序在执行程序的其余部分之前退出
- 为什么catch中的代码没有被执行
- C++从其他 constexpr 创建 lambda 不能按顺序执行 Constexpr
- 将执行、作业和WinAPI相乘
- 对字符数组中的元素执行逐位操作
- 为什么g++在未执行的代码处标记强制转换错误
- 在 C++11 中缺少对执行执行的"missing sentinel"警告