简体   繁体   English

我可以将nullptr用作Linux系统调用参数吗?

[英]Can I use nullptr as a Linux system call parameter?

I'm developing a user space application on Raspbian in C++11. 我正在C ++ 11中的Raspbian上开发用户空间应用程序。 ReSharper++ advises me to use nullptr instead of NULL in the following system call: ReSharper ++建议我在以下系统调用中使用nullptr而不是NULL

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

I think that I should stay with NULL because this library is dedicated for system programming in C. 我认为我应该保留NULL因为该库专用于C语言中的系统编程。

What is the best practice in this situation? 在这种情况下,最佳做法是什么?

Both NULL and nullptr will work fine. NULLnullptr都可以正常工作。 However, since this is syspro in C, I would go with NULL , because it's what I see more often (if not always) in that field. 但是,由于这是C语言中的syspro,因此我将使用NULL ,因为这是我在该字段中经常看到的(如果不是总是这样)。

If you check the reference of your system call, you will see that everywhere NULL is mentioned, not nullptr , something which you should expect (if not make sure you 'll read the following answer). 如果检查系统调用的引用 ,您会看到到处都提到NULL ,而不是nullptr ,这是您应该期望的(如果不能确保您将阅读以下答案)。

Check also NULL vs nullptr . 同时检查NULL vs nullptr

I would stay with nullptr because the intention is more clear. 我会留在nullptr上,因为意图更加明确。

There is a implicit conversion of nullptr to pointer for any type so you are definitely safe. 任何类型都有nullptr到指针的隐式转换,因此绝对安全。

cppreference.com: cppreference.com:

The keyword nullptr denotes the pointer literal. 关键字nullptr表示指针文字。 It is a prvalue of type std::nullptr_t. 它是std :: nullptr_t类型的prvalue。 There exist implicit conversions from nullptr to null pointer value of any pointer type and any pointer to member type. 存在从nullptr到任何指针类型以及指向成员类型的任何指针的null指针值的隐式转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM