From: "J.A. Magallon" <jamagallon@able.es>
To: Stevie O <stevie@qrpff.net>
Cc: Vincent Sweeney <v.sweeney@dexterus.com>,
vda <vda@port.imtp.ilyichevsk.odessa.ua>,
linux-kernel@vger.kernel.org
Subject: Re: [BUG] Bad #define, nonportable C, missing {}
Date: Thu, 22 Nov 2001 21:08:01 +0100 [thread overview]
Message-ID: <20011122210801.A1514@werewolf.able.es> (raw)
In-Reply-To: <01112112401703.01961@nemo> <3BFB9FAE.DB9B6003@dexterus.com> <5.1.0.14.2.20011121232051.01dab468@whisper.qrpff.net>
In-Reply-To: <5.1.0.14.2.20011121232051.01dab468@whisper.qrpff.net>; from stevie@qrpff.net on Thu, Nov 22, 2001 at 05:24:02 +0100
On 20011122 Stevie O wrote:
>At 12:35 PM 11/21/2001 +0000, Vincent Sweeney wrote:
>> > Bad code style. Bad name (sounds like 'module inc').
>> > I can't even tell from this define what the hell it is trying to do:
>> > x++ will return unchanged x, then we obtain (x mod y),
>> > then we store it into x... and why x++ then??!
>> > Alan, seems like you can help here...
>>
>>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)
>
>But x++ is postincrement though. That means the value of 'x' is inserted,
>and after the expression is evaluated, x is incremented. Right?
>
>If we were going to be semiobscure, wouldn't the correct code be
>
>#define MODINC(x,y) (x = ++x % y)
>
But the question is: Is this kind of code worth the discussion ? AFAIK,
gcc is enough smart to change *2 to <<1, so wouldn't it be smart to
detect a +1 and use and inc (and perhaps to detect that x is overwritten so it
can do the op in place).
So write it as
x = (x+1)%y
and make it readable.
--
J.A. Magallon # Let the source be with you...
mailto:jamagallon@able.es
Mandrake Linux release 8.2 (Cooker) for i586
Linux werewolf 2.4.15-pre9 #1 SMP Thu Nov 22 16:16:54 CET 2001 i686
next prev parent reply other threads:[~2001-11-22 20:08 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-21 12:40 [BUG] Bad #define, nonportable C, missing {} vda
2001-11-21 11:10 ` Andreas Schwab
2001-11-21 11:16 ` Tim Waugh
2001-11-21 12:31 ` Ragnar Hojland Espinosa
2001-11-21 13:40 ` Jan Hudec
2001-11-21 14:19 ` Andreas Schwab
2001-11-21 14:52 ` Alexander Viro
2001-11-21 18:23 ` Neil Booth
2001-11-21 12:35 ` Vincent Sweeney
2001-11-21 13:37 ` Jan Hudec
2001-11-21 13:52 ` Mathijs Mohlmann
2001-11-21 17:12 ` vda
2001-11-26 20:28 ` Alan Cox
2001-11-27 18:03 ` vda
2001-11-27 18:38 ` Andreas Dilger
2001-11-28 13:19 ` vda
2001-11-21 14:12 ` Richard B. Johnson
2001-11-21 14:33 ` Eric W. Biederman
2001-11-21 14:56 ` Alexander Viro
2001-11-21 14:59 ` Andreas Schwab
2001-11-21 15:48 ` Momchil Velikov
2001-11-21 16:52 ` vda
2001-11-21 14:24 ` Sean Hunter
2001-11-21 14:25 ` Andreas Schwab
2001-11-22 20:43 ` Chris Gray
2001-11-22 4:24 ` Stevie O
2001-11-22 11:46 ` Horst von Brand
2001-11-22 12:03 ` Alexander Viro
2001-11-22 20:08 ` J.A. Magallon [this message]
[not found] ` <01112311540300.00886@manta>
2001-11-23 14:43 ` J.A. Magallon
-- strict thread matches above, loose matches on Subject: below --
2001-11-27 19:03 Nathan Myers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20011122210801.A1514@werewolf.able.es \
--to=jamagallon@able.es \
--cc=linux-kernel@vger.kernel.org \
--cc=stevie@qrpff.net \
--cc=v.sweeney@dexterus.com \
--cc=vda@port.imtp.ilyichevsk.odessa.ua \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.