Re: SYSTEM(3)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 11/11/2018 20:02, Michael Kerrisk (man-pages) wrote:
On 11/11/18 5:38 PM, Jakub Wilk wrote:
* Jonny Grant <jg@xxxxxxxx>, 2018-11-11, 14:26:
BTW, C Spec says NULL is a pointer that doesn't have a type,

Not quite. NULL is a “null pointer constant”, which could be an integer,
not necessarily a pointer.

That said, the POSIX.1-2008 standard guarantees it's a pointer. (AFAICT,
the earlier standards did not guarantee this.)

On the other hand, NULL is not defined as a pointer in C++.

And also perhaps not in C? At least not historically; I'm not
sure if that's still true.

Since C90 NULL has been a void* I believe.

You're right, NULL shows up as "long int" on C++ and void* in C

Since C++11 7 years ago, C++ has used the nullptr keyword, which is void*

It is a shame C++ didn't follow void* style in C, possibly because C++ pre-dated C90 spec.


there is no need to cast it to (char *)   -- should that be taken out?

The execl*() functions are variadic, which makes them picky about
argument types. Theses casts are certainly needed when NULL is not
defined as a pointer.

Exactly.

It's less clear to me if they are still necessary when NULL is defined
as (void*)0.

No, I believe they're not.

Either way, I recommend keeping the cast for the sake of portability.

Exactly. You don't know how a particular implementation has
defined NULL. Could be `(void *) 0'. Or it could be just `0'.

As you say, better keep the cast for the old C++ code relying on #define NULL 0 from a C++ install.

Looks like no changes needed!

Jonny



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux