[lkml]   [2004]   [Jul]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: [PATCH] Use NULL instead of integer 0 in security/selinux/
    On Thu, 8 Jul 2004, Richard B. Johnson wrote:
    > On Thu, 8 Jul 2004, Herbert Xu wrote:
    > > What's wrong with using 0 as the NULL pointer?
    > Because NULL is a valid pointer value. 0 is not. If you were
    > to make 0 valid, you would use "(void *)0", which is what
    > NULL just happens to be in all known architectures so far,
    > although that could change in an alternate universe.

    False. "An integer constant expressions with the value 0, or such an
    expression cast to type void *, is called a null pointer constant. If a
    null pointer constant is assigned to or compared for equality with a
    pointer, the constant is converted to a pointer of that type", and "Any
    two null pointers shall compare equal."

    In other words, when you use 0 as a null pointer, you really do get a null
    pointer. If you are working on an architecture where the bit pattern of
    the integer 0 and null pointers are not the same, the compiler will
    perform the appropriate conversion for you, so it is always correct to
    define NULL as (void *)0.

    Personally, I always use 0 and NULL for integers and null pointers
    respectively, but that's because of long estalished conventions that make
    the code readabile, rather than anything to do with validity of the code.

    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

     \ /
      Last update: 2005-03-22 14:04    [W:4.328 / U:0.072 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site