我正在 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/