NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/44800: Misplaced parenthesis.



Am 02.04.11 21:24, schrieb Marc Balmer:
> Am 02.04.11 19:55, schrieb Mindaugas Rasiukevicius:
>> The following reply was made to PR kern/44800; it has been noted by GNATS.
>>
>> From: Mindaugas Rasiukevicius <rmind%netbsd.org@localhost>
>> To: David Laight <david%l8s.co.uk@localhost>, 
>> henning.petersen%t-online.de@localhost
>> Cc: gnats-bugs%NetBSD.org@localhost, netbsd-bugs%netbsd.org@localhost
>> Subject: Re: kern/44800: Misplaced parenthesis.
>> Date: Sat, 2 Apr 2011 18:54:03 +0100
>>
>>  David Laight <david%l8s.co.uk@localhost> wrote:
>>  >  On Wed, Mar 30, 2011 at 12:40:00PM +0000, 
>> henning.petersen%t-online.de@localhost
>>  > wrote:
>>  >  > >Number:         44800
>>  >  ...
>>  >  > -      if ((error = vte_dma_alloc(sc) != 0))
>>  >  > +      if ((error = vte_dma_alloc(sc)) != 0)
>>  >  
>>  >  I would fix all these by moving the assignment out of the if.
>>  >  > +      error = vte_dma_alloc(sc);
>>  >  > +      if (error != 0)
>>  >  
>>  >  The code is easier to read, and has shorter lines.
>>  
>>  Yes, I prefer such style as well (it's not exactly KNF, though).
>>  
>>      error = vte_dma_alloc(sc);
>>      if (error) {
>>              ...
>>      }
> 
> This is C, get over it.
> 
> The idiom 'if ((err = xxx()) != 0)' is quite common and total ok to use.

Actually, the real C fix would be to write

if ((error = vte_dma_alloc(sc)))

Unix functions return non-zero values to indicate failure for the exact
reason to allow for this concise and short idiom.  Checking for '!= 0'
is totally superfluous.


Home | Main Index | Thread Index | Old Index