Subject: Re: bin/19381: netstat shows negative percentage
To: David Laight <>
From: Andy Isaacson <>
List: netbsd-bugs
Date: 12/17/2002 18:56:41
On Mon, Dec 16, 2002 at 02:37:03PM +0000, David Laight wrote:
> 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
> it.

Neither ISO C89 nor ISO C99 has any ambiguity in the expression
"totused/(totmem/100)".  It must be evaluated "as if" totmem is divided
by 100, truncated to integer, and totused divided by the result; the
final result is also truncated to an integer.  See section 6.5.5 of
ISO/IEC 9899:1999 (The ISO C standard).

The compiler can generate any machine opcodes it wants, so long as the
result is correct according to the abstract specification of the
standard.  But the answer is not open to dispute.