linux-mips
[Top] [All Lists]

Re: [PATCH] Use NULL for pointer

To: linux-mips@linux-mips.org
Subject: Re: [PATCH] Use NULL for pointer
From: post@pfrst.de
Date: Fri, 13 Jul 2007 01:50:07 +0200 (CEST)
In-reply-to: <20070713.014949.55147875.anemo@mba.ocn.ne.jp>
Original-recipient: rfc822;linux-mips@linux-mips.org
Sender: linux-mips-bounce@linux-mips.org

Please excuse me, i couldn't restrain myself from commenting on this.
It's a pity, that a weird warning (which gcc version with what settings
did produce it ?) urges one to (re-)introduce this obsolescent macro.

"6.3.2.3 Pointers
 ...
 3 An integer constant expression 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
   to a pointer, the constant is converted to a pointer of that type..."

"7.17 Common definitions <stddef.h>
 ...
  NULL
 which expands to an implementation-defined null pointer constant..." 

And pre-ISO-Standard C compilers de-facto behaved the same way.

So, NULL simply isn't a "better" null pointer constant than plain 0. It
is a relic from the (good old ?) times, when no prototypes were available,
and one needed another way to ensure the proper type (width) of function
arguments.  (C++ could do without it from the very beginning)
In other words, the code seems to be more correct than the warning.


In the hope of neither having been too much off-topic nor having offended
anyone...

peter


On Fri, 13 Jul 2007, Atsushi Nemoto wrote:

> Date: Fri, 13 Jul 2007 01:49:49 +0900 (JST)
> From: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
> To: linux-mips@linux-mips.org
> Cc: ralf@linux-mips.org
> Subject: [PATCH] Use NULL for pointer
> 
> This fixes a sparse warning:
> 
> arch/mips/kernel/traps.c:376:44: warning: Using plain integer as NULL pointer
> 
> Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
> ---
> diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
> index 80ea4fa..5e9fa83 100644
> --- a/arch/mips/kernel/traps.c
> +++ b/arch/mips/kernel/traps.c
> @@ -373,7 +373,7 @@ asmlinkage void do_be(struct pt_regs *regs)
>               action = MIPS_BE_FIXUP;
>  
>       if (board_be_handler)
> -             action = board_be_handler(regs, fixup != 0);
> +             action = board_be_handler(regs, fixup != NULL);
>  
>       switch (action) {
>       case MIPS_BE_DISCARD:
> 
> 
> 


<Prev in Thread] Current Thread [Next in Thread>