"Christopher Benson-Manica" <(E-Mail Removed)> wrote in message

news:bkv4bb$pvl$(E-Mail Removed)...

> Richard Heathfield <(E-Mail Removed)> spoke thus:

>

> >> printf("The range is %d\n", max (int1, (max (int2, int3)))

> >> - min (int1, (min (int2, int3))));

>

> > OP: now that Mr Zimmerman has trashed any value that might have remained
in

> > your homework assignment, see if you can work out ON YOUR OWN why the
above

> > printf assumes too much.

>

> I'm having a tough time figuring out what it assumes that's inadvisable.
max

> and min always return integers, so the program will never crash.
It might not crash (actually nobody said it would, but it could),

but will it always give accurate results even when 'int1', 'int2'

and 'int3' each have a valid value? What output do you get from

the following (at the risk of further annoying Richard

) :

[compile with implementation where sizeof(int) >= 4]

#include <limits.h>

#include <stdio.h>

int min(int lhs, int rhs)

{

return lhs < rhs ? lhs : rhs;

}

int max(int lhs, int rhs)

{

return lhs > rhs ? lhs : rhs;

}

int main()

{

int int1 = 500000000;

int int2 = -1000000000;

int int3 = -2000000000;

double dmin = int3; /* used below */

double dmax = int1; /* " " */

printf("INT_MIN == %11d\n", INT_MIN);

printf("INT_MAX == %11d\n", INT_MAX);

printf("int1 == %11d\n"

"int2 == %11d\n"

"int3 == %11d\n",

int1, int2, int3);

printf("max(%11d, (max(%11d, %11d))) == %11d\n"

"min(%11d, (min(%11d, %11d))) == %11d\n",

int1, int2, int3, max(int1, (max(int2, int3))),

int1, int2, int3, min(int1, (min(int2, int3))));

printf("The range is %11d\n", max (int1, (max (int2, int3)))

- min (int1, (min (int2, int3))));

printf("%.0f - %.0f == %.0f\n", dmax, dmin, dmax - dmin);

return 0;

}

-Mike

.. And as far

> as I can tell,
How far did you test?

>it always produces correct results...
Not *always*.

>so help me out here...
See above.

-Mike