RE: C and side-effects

From: Rik van Riel (riel@conectiva.com.br)
Date: Thu May 04 2000 - 07:18:55 EST


On Wed, 3 May 2000, Robert M. Love wrote:
> > Rik van Riel wrote:
> >
> > > I'm not that good at C, mas aren't expressions with side-effects
> > > ill-defined? How can we be sure (short of tracking the gcc
> > > mailing lists) that i will be incremented after the left part of
> > > the test?
> >
> > Because it is defined in the C standard?
>
> maybe im reading the thread wrong, but Cesar is saying the code
> while ((mm->swap_cnt << 2 * (i + 1) < max_cnt) && i++ < 10)
> does not guarentee that the expression to the left of && occurs
> prior to "i++" -- and he is Right, because the C standard does
> *not* specify this. proof is in K&R, where they explicitly
> mention compiler design or optimization can change compound
> statement ordering in the resulting machine code. thus, i agree
> an alternative should be considered in the kernel.

If that were true, we would have run into problems with
statements like the following LONG ago...

      if (!p->swappable || !mm || mm->rss <= 0)
              continue;

(because mm->rss could be dereferenced before we test
if mm is a valid pointer ... luckily the order in which
the clauses for _logical_ operands are tested is clearly
defined ... maybe you're confusing them with bitwise
operators?)

Rik

--
The Internet is not a network of computers. It is a network
of people. That is its real strength.

Wanna talk about the kernel? irc.openprojects.net / #kernelnewbies http://www.conectiva.com/ http://www.surriel.com/

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun May 07 2000 - 21:00:14 EST