<<< Date Index >>>     <<< Thread Index >>>

Re: Little code cleanup



On Thu, 2008-03-20 15:39:43 +0100, Vincent Lefevre wrote:
> [..]
> 
> Consider the following program:
> 
> int main (void)
> {
>   char a[1], *b;
>   b = a;
>   if (a == 0)
>     return 1;
>   else if (a == (void *) 0)
>     return 2;
>   else if (b == 0)
>     return 3;
>   else if (b == (void *) 0)
>     return 4;
>   return 0;
> }
> 
> gcc gives a warning only for the test "a == 0":

I suppose gcc suspects "a == 0" being a typing error and should
actually read "a[0] == 0".

As long as gcc knows 'a' is an array, giving a warning seems sensible
to me (as the programmer is supposed to know this as well, and testing
for 'a' being zero doesn't make sense then).

Ludolf

-- 

---------------------------------------------------------------
Ludolf Holzheid             Tel:    +49 621 339960
Bihl+Wiedemann GmbH         Fax:    +49 621 3392239
Floßwörthstraße 41          e-mail: lholzheid@xxxxxxxxxxxxxxxxx
D-68199 Mannheim, Germany
---------------------------------------------------------------