简体   繁体   中英

Can I use nullptr as a Linux system call parameter?

I'm developing a user space application on Raspbian in C++11. ReSharper++ advises me to use nullptr instead of NULL in the following system call:

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.

What is the best practice in this situation?

Both NULL and nullptr will work fine. 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.

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).

Check also NULL vs nullptr .

I would stay with nullptr because the intention is more clear.

There is a implicit conversion of nullptr to pointer for any type so you are definitely safe.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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