gcc questions

Michael Hennebry hennebry at web.cs.ndsu.nodak.edu
Sun Nov 27 17:30:15 UTC 2005


On Sun, 27 Nov 2005, Ian Malone wrote:

> There are two separate things going on:
>
> #include <math.h>
>
> Includes declarations for the functions in the library, it is not the
> library itself.  It is equivalent to putting declarations like:
>
> double sqrt(double);
>
> at the top of you source file (except you /should/ use the include,
> because it will get them right), telling the compiler you are going
> to us some functions, they look like this, but you're not putting them
> in this file.
>
> The library itself contains the compiled function bodies, the
> double sqrt(double squared) {
>    double root;
>    /* do clever things to get root = square root of squared
>     * ... */
>    return root;
> }

On some systems this is complicated by the
fact that sqrt is a *standard* function.
The standard says what sqrt does.
x=sqrt(y) might not result in a function call.
It might result in a single instruction if
the processor has such an instruction.
In that case (apparently not the one under discussion),
there would be no undefined reference.
A hardware sin and cos is more rare.
Also the compiler might put something in the object file that
would tell the linker to look for the standard math library.

If you needed matrix_multiply from a library,
you would need to tell the linker where to find it.
matrix_multiply is not a standard function.


BTW "math.h" != <math.h>
I've seen code in which quotes and angle brackets were used interchangeably.
Usually it works.

-- 
Mike   hennebry at web.cs.ndsu.NoDak.edu
"I AM DEATH, NOT TAXES.  *I* ONLY TURN UP ONCE."  --  Death




More information about the fedora-list mailing list