[LCP]Rounding questions

Bill Rausch William.Rausch at numerical.com
Sat Sep 7 17:31:26 UTC 2002


At 3:10 PM -0400 9/5/02, Chuck Martin wrote:
>On Thu, Sep 05, 2002 at 12:36:39PM -0500, Steve Baker wrote:
>>    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);
>
>Thank you!  This works.  Do you happen to know why rint() works without
>doing this?  I can't seem to find a prototype for it anywhere, including
>math.h.
>
>>    This is a good reminder of why you have to prototype your functions!
>
>Yes, but I never expected to have to prototype a function in a standard
>library.
>
>Now this brings me to the other question I asked when I started this
>thread.  How portable is this?  The man page says it conforms to C99,
>but I'm not up on all of the standards and where they're all used.
>Will using this instead of my own rounding routine cause problems in
>portability, and if so, to what extent?
>
>Chuck

If the function has a man page and the man page refers to a system 
header and the system header does not contain the prototype, then the 
system header is broke and needs fixing.  Who is responsible for 
fixing it?  I haven't a clue.

If rint() is supposed to return an integer and accepts a double as an 
argument, then technically it doesn't need a prototype since that is 
default behavior for K&R C which ANSI C intentionally followed. 
Unprototyped functions are always assumed to return ints.  They are 
also assumed to take arguments that are either ints or doubles and 
the compiler will automatically convert floats to doubles when 
passing args to a non-prototyped function.


-- 
Bill Rausch, Software Development, UNIX, Mac, Windows
Numerical Applications, Richland, WA  509-943-0861 x302




More information about the linuxCprogramming mailing list