[LCP]Rounding questions

Steve Baker ice at mama.indstate.edu
Fri Sep 6 03:41:05 UTC 2002


  It seems perplexing, but the problem is that round is not prototyped in
math.h, or anywhere for that matter.  This is clearly a glibc maintainer
issue.  Add to your program at the top:

double round(double);

  And you're good to go.  Unprototyped functions default to returning int, but
the round() function was no doubt pushing doubles onto the stack, but printf()
was probably pulling the data off the stack as ints. Stack strangness ensues
and you only stumble onto the right value every third argument I would
surmise.  If I cared to know i386, I could probably give you a much better
(and probably more correct) answer, but I'm a C programmer not an assembler.

  This is a good reminder of why you have to prototype your functions!

								- Steve




More information about the linuxCprogramming mailing list