c++ - 我可以使用 nullptr 作为 Linux 系统调用参数吗?

标签 c++ c linux c++11 system-calls

我正在 Raspbian 上使用 C++11 开发用户空间应用程序。 ReSharper++ 建议我在以下系统调用中使用 nullptr 而不是 NULL:

auto ret = timerfd_settime(this->_timer_fd, 0, &timeout, NULL);
assert(0 == ret);

我认为我应该继续使用 NULL,因为这个库专用于 C 语言的系统编程。

这种情况下的最佳做法是什么?

最佳答案

我会继续使用 nullptr,因为意图更明确。

nullptr 会隐式转换为任何类型的指针,因此绝对安全。

cppreference.com:

The keyword nullptr denotes the pointer literal. It is a prvalue of type std::nullptr_t. There exist implicit conversions from nullptr to null pointer value of any pointer type and any pointer to member type.

关于c++ - 我可以使用 nullptr 作为 Linux 系统调用参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32417330/

相关文章:

c++ - Boost 目录迭代器 "no such file or directory"

c - 在 C 数组中打印非重复项

c++ - C++代码中的C

c - 使用 execvp() 在递归 cp 中未扩展通配符

linux - 使用 bash 从文件中获取随机字节数?

c++ - SFML - 无法加载图像 - 无法打开文件 - LINUX

c++ - ISAPI 和 Visual C++ 2010

c++ - Eclipse CDT 错误 : Unable to compile

c++ - 限制用户输入的数字只能保留到小数点后 2 位 C/C++

c++ - 将二叉树存储在数组中,缺失位置为空值