mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Horst von Brand <vonbrand@inf.utfsm.cl>
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 08:46:08 -0300	[thread overview]
Message-ID: <200111221146.fAMBk8XF006908@pincoya.inf.utfsm.cl> (raw)
In-Reply-To: Message from Stevie O <stevie@qrpff.net>  of "Wed, 21 Nov 2001 23:24:02 CDT." <5.1.0.14.2.20011121232051.01dab468@whisper.qrpff.net>

Stevie O <stevie@qrpff.net> said:
> 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?

Nope. x++ increments x sometime (not defined when) after taking the value. 

   x = x++ % y

is wrong: There is just one sequence point at the end of the expression,
and x is modified twice in between (++ and =). If this gives the same as:

   x = (x + 1) % y

gcc is smoking potent stuff... but it could legally do anything at all.
-- 
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                     Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria              +56 32 654239
Casilla 110-V, Valparaiso, Chile                Fax:  +56 32 797513

  reply	other threads:[~2001-11-22 11:47 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-21 12:40 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 [this message]
2001-11-22 12:03     ` Alexander Viro
2001-11-22 20:08   ` J.A. Magallon
     [not found]     ` <01112311540300.00886@manta>
2001-11-23 14:43       ` J.A. Magallon
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=200111221146.fAMBk8XF006908@pincoya.inf.utfsm.cl \
    --to=vonbrand@inf.utfsm.cl \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®