64-bit NULL: a followup

Bruce Evans bde at zeta.org.au
Fri Nov 28 21:39:23 PST 2003


On Fri, 28 Nov 2003, Marcel Moolenaar wrote:

> Notice the "st8".  Since NULL is a pointer constant, programmers do
> (implicitly) expect it to have the same width as a pointer type and
> thus do not cast it to a pointer type or an integer type that has a
> width larger or equal to a pointer type.

FreeBSD programmers would never do that ;-), since style(9) requires
casting of NULL in function args and mentions this point.  (This part
of style(9) was written before everything in FreeBSD was prototyped,
so the cast was required even for non-variadic functions.)

> So, the bottomline is that we currently do have third-party code that
> fails to run on ia64 (and possibly other 64-bit platforms) due to the
> fact that NULL is defined as 0.
>
> Since Erik thinks 0 and 0L are both perfectly good definitions for
> NULL and Tony emphasizes that NULL is an integer expression, I think
                                     ^^ may be
> we should change the definition of NULL to 0L to improve portability
> to FreeBSD/LP64. It will definitely fix known breakages on ia64.

This would be bogus.  Long doesn't have the same width as `void *' on all
machines.  ((void *)0) is better, but I wouldn't change it, except
locally to trap errors.  __builtin_null would be better for trapping
errors.

Bruce


More information about the freebsd-standards mailing list