Re: SYSTEM(3)

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

 



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.

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

Thanks,

Michael

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/




[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