public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* (0 == foo), rather than (foo == 0)
@ 2004-03-10  6:16 Godbole, Amarendra (GE Consumer & Industrial)
  2004-03-10 10:34 ` Bernd Petrovitsch
  2004-03-10 18:02 ` Randy.Dunlap
  0 siblings, 2 replies; 49+ messages in thread
From: Godbole, Amarendra (GE Consumer & Industrial) @ 2004-03-10  6:16 UTC (permalink / raw)
  To: linux-kernel

Hi,

While writing code, the assignment operator (=) is many-a-times confused with the comparison operator (==) resulting in very subtle bugs difficult to track. To keep a check on this -- the constant can be written on the LHS rather than the RHS which will result in a compile time error if wrong operator is used.

Is this an encouraged practice while writing any code for the kernel ? Or is this choice left to the developer ? I was unable to find any reference to it in the CodingStyle document. I did find some code under drivers/ which used (NULL == foo) and similar constructs. 

Can this be added to the CodingStyle document ?

Cheers,
Amarendra

--
#include <std$disclaimer.h>

^ permalink raw reply	[flat|nested] 49+ messages in thread
* RE: (0 == foo), rather than (foo == 0)
@ 2004-03-11  4:04 Godbole, Amarendra (GE Consumer & Industrial)
  0 siblings, 0 replies; 49+ messages in thread
From: Godbole, Amarendra (GE Consumer & Industrial) @ 2004-03-11  4:04 UTC (permalink / raw)
  To: linux-kernel

> As a result, using the former just tends to increase peoples 
> confusion by making code harder to read, which in turn tends 
> to increase the chance of bugs.

Kindly don't insult the kernel developers' with such statements. ;-)
They are smart enough to understand such constructs, which, I 
deduce from what someone said earlier in this thread. So no 
confusion  would prevail here...[take it in a lighter vein folks, I 
am kidding.]

> So don't do it. The kind of bug that the "0 == x" syntax 
> protects against is LESS LIKELY to happen than the kind of 
> bug it tends to cause.

Agreed and understood. Thanks.

Sincere apologies for my previous ``non-text wrapped'' post. This
won't happen henceforth.

Cheers,
Amarendra

--
Picture Perfect Engineering / These opinions are mine.

^ permalink raw reply	[flat|nested] 49+ messages in thread
[parent not found: <1y5oc-8cr-1@gated-at.bofh.it>]
[parent not found: <1ypPV-5N2-3@gated-at.bofh.it>]

end of thread, other threads:[~2004-03-12 12:19 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-10  6:16 (0 == foo), rather than (foo == 0) Godbole, Amarendra (GE Consumer & Industrial)
2004-03-10 10:34 ` Bernd Petrovitsch
2004-03-10 18:02 ` Randy.Dunlap
2004-03-10 18:33   ` Richard B. Johnson
2004-03-10 18:50     ` [OT] " David Ford
2004-03-10 19:06       ` Roland Dreier
2004-03-10 19:26         ` David Ford
2004-03-10 21:26           ` Roland Dreier
2004-03-10 22:03             ` Måns Rullgård
2004-03-11 23:12               ` Bill Davidsen
2004-03-10 19:23       ` Richard B. Johnson
2004-03-10 19:31         ` David Ford
2004-03-10 23:20           ` Frank v Waveren
2004-03-10 23:33             ` Måns Rullgård
2004-03-11  2:14             ` David Ford
2004-03-11 15:06             ` Valdis.Kletnieks
2004-03-10 23:10         ` Peter Williams
2004-03-10 21:29       ` viro
2004-03-10 22:20         ` David Ford
2004-03-10 22:42           ` Richard B. Johnson
2004-03-11  0:33             ` Micha Feigin
2004-03-11 10:47               ` Giuseppe Bilotta
2004-03-10 22:49           ` Stefan Smietanowski
2004-03-10 23:14             ` David Ford
2004-03-10 23:28               ` Måns Rullgård
2004-03-10 23:47               ` Stefan Smietanowski
2004-03-10 21:34       ` Matthew Garrett
2004-03-10 23:00     ` Peter Williams
2004-03-11  0:16       ` Randy.Dunlap
2004-03-11  2:36       ` Linus Torvalds
2004-03-11  3:08         ` Peter Williams
2004-03-11  3:19           ` Linus Torvalds
2004-03-11  4:40             ` Stefan Smietanowski
2004-03-11  9:48               ` Måns Rullgård
2004-03-11 10:29                 ` Stefan Smietanowski
2004-03-11 15:18                 ` Andreas Schwab
2004-03-11 17:42                   ` Stefan Smietanowski
2004-03-11 23:05                     ` Bill Davidsen
2004-03-11  6:50         ` Willy Tarreau
2004-03-11  7:36           ` Peter Williams
2004-03-11 15:03     ` Valdis.Kletnieks
2004-03-11 15:22       ` Richard B. Johnson
2004-03-11 15:48         ` Valdis.Kletnieks
  -- strict thread matches above, loose matches on Subject: below --
2004-03-11  4:04 Godbole, Amarendra (GE Consumer & Industrial)
     [not found] <1y5oc-8cr-1@gated-at.bofh.it>
     [not found] ` <1ygjH-3LE-31@gated-at.bofh.it>
     [not found]   ` <1ygMH-4eu-21@gated-at.bofh.it>
     [not found]     ` <1yzZ9-1qq-43@gated-at.bofh.it>
     [not found]       ` <1yAs0-1P6-7@gated-at.bofh.it>
     [not found]         ` <1yALu-288-5@gated-at.bofh.it>
2004-03-11 16:41           ` Chip Salzenberg
     [not found] <1ypPV-5N2-3@gated-at.bofh.it>
2004-03-11 16:44 ` Chip Salzenberg
2004-03-11 23:57   ` Peter Williams
2004-03-12  1:51   ` Chris Johns
2004-03-12 12:21     ` Richard B. Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox