From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752044AbYLYGRm (ORCPT ); Thu, 25 Dec 2008 01:17:42 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751151AbYLYGRa (ORCPT ); Thu, 25 Dec 2008 01:17:30 -0500 Received: from a-sasl-fastnet.sasl.smtp.pobox.com ([207.106.133.19]:57499 "EHLO sasl.smtp.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750948AbYLYGR3 (ORCPT ); Thu, 25 Dec 2008 01:17:29 -0500 From: Junio C Hamano To: Krzysztof Halasa Cc: Linus Torvalds , Harvey Harrison , =?utf-8?B?SMOla29uIEzDuHZkYWw=?= , Hannes Eder , netdev@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 02/27] drivers/net: fix sparse warnings: make do-while a compound statement References: <20081222191259.11807.53190.stgit@vmbox.hanneseder.net> <20081222191507.11807.50794.stgit@vmbox.hanneseder.net> <1230053186.1447.9.camel@brick> Date: Wed, 24 Dec 2008 22:17:15 -0800 In-Reply-To: (Krzysztof Halasa's message of "Wed, 24 Dec 2008 03:03:50 +0100") Message-ID: <7vd4fgdbis.fsf@gitster.siamese.dyndns.org> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Pobox-Relay-ID: B3EF1220-D24B-11DD-82B3-5720C92D7133-77302942!a-sasl-fastnet.pobox.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Krzysztof Halasa writes: > Linus Torvalds writes: > ... >> Another example of "common vs non-common" is this: >> >> if (0 <= x) >> do something.. >> >> is something that crazy people do (sadly, one of the crazy people taught >> the git maintainer C programming, so now even sane people do it). It's >> crazy because it's uncommon, which means that most people have to think >> about it A LOT MORE than about >> >> if (x >= 0) >> do something.. > > No. It's crazy not because it's uncommon, but because this is how we > have been taught in school. > > I don't know reasons for "0 >= x" but I know one for > if (0 == x) > do something.. > > It's because people sometimes write "=" instead of "==" and "0 = x" > doesn't make sense to gcc. It does not have anything to do with the assignment confusion. It is "textual order should reflect actual order" (aka "have number line in your head when you write your comparison conditional"): http://thread.gmane.org/gmane.comp.version-control.git/3903/focus=4126 Even if it may make logical sense, I would not suggest using it when other people are not familiar with the convention, though. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Junio C Hamano Date: Thu, 25 Dec 2008 06:17:15 +0000 Subject: Re: [PATCH 02/27] drivers/net: fix sparse warnings: make do-while a Message-Id: <7vd4fgdbis.fsf@gitster.siamese.dyndns.org> List-Id: References: <20081222191259.11807.53190.stgit@vmbox.hanneseder.net> <20081222191507.11807.50794.stgit@vmbox.hanneseder.net> <1230053186.1447.9.camel@brick> In-Reply-To: (Krzysztof Halasa's message of "Wed, 24 Dec 2008 03:03:50 +0100") MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Krzysztof Halasa Cc: Linus Torvalds , Harvey Harrison , =?utf-8?B?SMOla29uIEzDuHZkYWw=?= , Hannes Eder , netdev@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Krzysztof Halasa writes: > Linus Torvalds writes: > ... >> Another example of "common vs non-common" is this: >> >> if (0 <= x) >> do something.. >> >> is something that crazy people do (sadly, one of the crazy people taught >> the git maintainer C programming, so now even sane people do it). It's >> crazy because it's uncommon, which means that most people have to think >> about it A LOT MORE than about >> >> if (x >= 0) >> do something.. > > No. It's crazy not because it's uncommon, but because this is how we > have been taught in school. > > I don't know reasons for "0 >= x" but I know one for > if (0 = x) > do something.. > > It's because people sometimes write "=" instead of "=" and "0 = x" > doesn't make sense to gcc. It does not have anything to do with the assignment confusion. It is "textual order should reflect actual order" (aka "have number line in your head when you write your comparison conditional"): http://thread.gmane.org/gmane.comp.version-control.git/3903/focusA26 Even if it may make logical sense, I would not suggest using it when other people are not familiar with the convention, though.