Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Wed, 21 Nov 2001 10:14:14 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Wed, 21 Nov 2001 10:14:04 -0500 Received: from [195.66.192.167] ([195.66.192.167]:19212 "EHLO Port.imtp.ilyichevsk.odessa.ua") by vger.kernel.org with ESMTP id ; Wed, 21 Nov 2001 10:13:49 -0500 Content-Type: text/plain; charset=US-ASCII From: vda To: Mathijs Mohlmann , Jan Hudec , Alan Cox Subject: Re: [BUG] Bad #define, nonportable C, missing {} Date: Wed, 21 Nov 2001 17:12:27 +0000 X-Mailer: KMail [version 1.2] Cc: linux-kernel@vger.kernel.org In-Reply-To: In-Reply-To: MIME-Version: 1.0 Message-Id: <01112117122701.02798@nemo> Content-Transfer-Encoding: 7BIT Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday 21 November 2001 13:52, Mathijs Mohlmann wrote: > On 21-Nov-2001 Jan Hudec wrote: > >> Go read up on C operator precedence. Unary ++ comes before %, so if we > >> rewrite the #define to make it more "readable" it would be #define > >> MODINC(x,y) (x = (x+1) % y) > > > > *NO* > > MODINC(x,y) (x = (x+1) % y) > > is correct and beaves as expected. Unfortunately: > > MODINC(x,y) (x = x++ % y) > > is a nonsence, because the evaluation is something like this > > x++ returns x > > x++ % y returns x % y > > x is assigned the result and it's incremented IN UNDEFINED ORDER!!! > > AFAIK the ANSI C spec explicitly undefines the order. > > in fact, gcc does (according to my tests): > MODINC(x,y) (x = (x % y) + 1) drivers/message/i2o/i2o_config.c:#define MODINC(x,y) (x = x++ % y) Alan, can you clarify what this macro is doing? What about making it less confusing? -- vda - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/