From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751445AbbEZSa4 (ORCPT ); Tue, 26 May 2015 14:30:56 -0400 Received: from e36.co.us.ibm.com ([32.97.110.154]:53302 "EHLO e36.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751126AbbEZSav (ORCPT ); Tue, 26 May 2015 14:30:51 -0400 Date: Tue, 26 May 2015 11:30:45 -0700 From: "Paul E. McKenney" To: Nicholas Mc Guire Cc: Joe Perches , Steven Rostedt , Nicholas Mc Guire , Lai Jiangshan , Josh Triplett , Mathieu Desnoyers , linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC] rcu: change return type to bool Message-ID: <20150526183045.GP5989@linux.vnet.ibm.com> Reply-To: paulmck@linux.vnet.ibm.com References: <1432392472-20702-1-git-send-email-hofrat@osadl.org> <20150523185820.13b5ad82@gandalf.local.home> <20150524072711.GA17508@opentech.at> <1432453318.2846.16.camel@perches.com> <20150524081018.GB17508@opentech.at> <1432456713.2846.23.camel@perches.com> <20150524084650.GA21828@opentech.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150524084650.GA21828@opentech.at> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15052618-0021-0000-0000-00000ADD43F8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 24, 2015 at 10:46:50AM +0200, Nicholas Mc Guire wrote: > On Sun, 24 May 2015, Joe Perches wrote: > > > On Sun, 2015-05-24 at 10:10 +0200, Nicholas Mc Guire wrote: > > > On Sun, 24 May 2015, Joe Perches wrote: > > > > > > > On Sun, 2015-05-24 at 09:27 +0200, Nicholas Mc Guire wrote: > > > > > On Sat, 23 May 2015, Steven Rostedt wrote: > > > > [] > > > > > > > - return sum; > > > > > > > + return !!sum; > > > > > > > > > > > > Hmm I wonder if gcc is smart enough to do the above without the need > > > > > > for !!? That is, will it turn to !! because the return of the function > > > > > > is bool, or does gcc complain about it not being bool without the !!? > > > > > > Not a criticism of the patch, just a curiosity. > > > > > > > > > > > gcc will not complain if you assign a unsigned long to a boolean > > > > > as I understand it it is a macro and is not doing any type > > > > > checking/promotion at all - so anything can be assigned to a bool > > > > > without warning (including double and pointers). > > > > > The !! will though always make the type compatible with int so it is > > > > > a well defined type atleast as far as __builtin_types_compatible_p() > > > > > goes, and !! also makes static code checkers happy (that are maybe not > > > > > as smart as gcc) and it does make the intent of sum being treated > > > > > as boolean here clear. > > > > > > > > 6.3.1.2 Boolean type > > > > > > > > When any scalar value is converted to _Bool, the result is 0 if the > > > > value compares equal to 0; otherwise, the result is 1. > > > > > > > As I understand this applies to arithmetic operations so for > > > bool x = false; int i = 42; x += i; x is defined to be true > > > but here it is the return type and not an arithmetic operation > > > so does this apply here without the !!? > > > > Yes, it does. return is an implicit conversion. > > > > 6.8.6.4 The return statement > > > > 3 If a return statement with an expression is executed, the value of > > the expression is returned to the caller as the value of the function > > call expression. If the expression has a type different from the > > return type of the function in which it appears, the value is > > converted as if by assignment to an object having the return type of > > the function. > > > get it - thanks for the clarification ! Hello, Nicholas, Were you planning to send an updated patch? Thanx, Paul