ol*****@inspire.net.nz (Old Wolf) writes:

Da*****@cern.ch (Dan Pop) wrote:

I have removed the library references from the following quote from C99's

foreword:

Major changes from the previous edition include:

- reliable integer division

What does this mean exactly?

C89 (draft):

----------------------------------------------------------------------

The result of the / operator is the quotient from the division of

the first operand by the second; the result of the % operator is the

remainder. In both operations, if the value of the second operand is

zero, the behavior is undefined.

When integers are divided and the division is inexact, if both

operands are positive the result of the / operator is the largest

integer less than the algebraic quotient and the result of the %

operator is positive. If either operand is negative, whether the

result of the / operator is the largest integer less than the

algebraic quotient or the smallest integer greater than the algebraic

quotient is implementation-defined, as is the sign of the result of

the % operator. If the quotient a/b is representable, the expression

(a/b)*b + a%b shall equal a .

----------------------------------------------------------------------

C99:

----------------------------------------------------------------------

5 The result of the / operator is the quotient from the division

of the first operand by the second; the result of the %

operator is the remainder. In both operations, if the value

of the second operand is zero, the behavior is undefined.

6 When integers are divided, the result of the / operator is the

algebraic quotient with any fractional part discarded.87) If

the quotient a/b is representable, the expression (a/b)*b +

a%b shall equal a.

87) This is often called ``truncation toward zero''.

----------------------------------------------------------------------

--

int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\

\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\

);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\

);}return 0;}