On Tuesday 19 June 2007 20:54:09 Eduardo Sanz-Garcia wrote:
> Topher wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > Eduardo Sanz-Garcia wrote:
> >> If math.h is part of the C standard library why I need to use the
> >> corresponding library to compile:
> >> gcc -*lm* codethatusemathfunctions.c
> >
> > I don't believe that you do. Do you have an example?
>
> The math function is floor()
>
> /*================
> Include file
> ================*/
> #include <math.h>
> #include <stdio.h>
> #include <unistd.h>
>
>
> int main()
> {
> float real_number=9.9;
> int real_rounded_to_int;
>
> real_rounded_to_int = (int) floor(real_number);
>
> return real_rounded_to_int;
> }
>
Linking to libm (yes, that's what the library is called) is necessary because
libc (the standard library) doesn't include the math functions. The math
functions are separated because there are many programs that don't need them,
only the libc stuff (usually not all of that, either). Mainly an optimization
from the early UNIX days, but since the minor inconvenience of adding -lm to
compile commands is rather small, libc and libm were never re-merged (in
fact, this would cause backward-compatibility issues, as some pieces of
software depend on the separation of libc and libm).
--- Mike Larsen
--
Politicians are like diapers...
they should be changed often, and for the same reason
The cure for boredom is curiosity.
There is no cure for curiosity.
-- Dorothy Parker
--------------------
BYU Unix Users Group
http://uug.byu.edu/
The opinions expressed in this message are the responsibility of their
author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG.
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list