Subject: Re: bin/19381: netstat shows negative percentage
To: None <email@example.com, firstname.lastname@example.org>
From: David Laight <email@example.com>
Date: 12/16/2002 14:37:03
On Sat, Dec 14, 2002 at 02:24:39PM -0500, Greg A. Woods wrote:
> [ On Saturday, December 14, 2002 at 12:17:13 (+0100), Martin Husemann wrote: ]
> > Subject: Re: bin/19381: netstat shows negative percentage
> > On Sat, Dec 14, 2002 at 10:59:44AM +0000, David Laight wrote:
> > > + totpct = (totmem < 100) ? 0 : totused/(totmem/100));
> > > to avoid nasty FP arithmetic.
> > I keep forgetting what the consensus was on the final C 99 standard: does
> > this force evaluation order? ISTR only assigning to temporaries did the
> > trick, while this allows the optimizer to rearange things.
> If ?: doesn't evaluate the test expression first then the language is not C
> Besides, in the above there are no worries anyway!
The :? is required not to do anything from the unwanted half
that has side effects - in this case a possible divide by zero exception.
The re-ordering issue is whether the compiler is allowed to
evaluate totused/(totmem/100) as (totused*100)/totmem.
IIRC K&R C did allow re-ordering, and the C99 standard disallows
David Laight: firstname.lastname@example.org