Christian Weisgerber <na...@mips.inka.de> wrote:

> NULL is not magic.  We #define NULL to 0.  It is 0 that is automatically
> treated as a null pointer _in pointer contexts_.  If a function has
> a variable number of arguments, like execlp() in this case, the
> compiler can't know if you are passing 0 the integer or 0 the null
> pointer.  It defaults to the former, that's why the cast is needed.

A further note:

On OpenBSD, the null pointer has a zero bit pattern, so the only
difference between 0 and (void *)0 is that these are 32 and 64-bit
values, respectively, on our LP64 platforms.

In practice, our LP64 architectures pass the first handful of
function arguments in registers.  One argument in each 64-bit
register, and if you load a 32-bit value into a register it is
(sign-)extended to 64 bits.  In most cases this will save your ass
if you erroneously pass 0 in place of (void *)0 to a variable
argument function.

Do *not* rely on this.

-- 
Christian "naddy" Weisgerber                          na...@mips.inka.de

Reply via email to