delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/14/02:47:38

Date: Tue, 14 Apr 1998 09:44:15 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: pokornp AT math DOT vscht DOT cz
cc: djgpp AT delorie DOT com
Subject: Re: Differences between -lm and not -lm
In-Reply-To: <6gtk2o$bnf$1@news.vscht.cz>
Message-ID: <Pine.SUN.3.91.980414094358.2344G-100000@is>
MIME-Version: 1.0

On 13 Apr 1998 pokornp AT math DOT vscht DOT cz wrote:

> In HP-UX man pow gives 
>       double pow(double x, double y);
> so 10 should be 10.0 as an argument to pow, shouldn't it ?

Welcome to the brave new world of ANSI C compilers!  If your program
says "#include <math.h>", the compiler sees the prototype of `pow'.
It then automagically converts integer arguments to double before
calling `pow'.  That is one reason to *always* include the headers
with prototypes of all the functions you are calling.

> I do not understand the reason for having two versions of pow functions.
> HP-UX cc gives error when pow is called without -lm, which I find correct.

The reason is that lots of DOS/Windows users are deeply entrenched in
the legacy of PC compilers which don't have a separate math library.
Previous versions of DJGPP had a separate libm.a which triggered a lot
of classic why-doesn't-my-program-which-calls-pow-works questions
(because people forget to say -lm).  So now math functions are in
libc.a.  Users which make a point of adding -lm to their command lines
are rewarded by linking in better versions of these functions.  But
the versions in libc.a are good enough for every purpose except some
marginal cases, where you test the last bit of the floating-point
accuracy.

> Can you, please, explain to me the difference between DJPGG and gnu C ?
> I thought DJPGG is just a port of gcc, i.e. a special implementation ?

You are confusing a compiler with the libraries which go with it.
These two need not come from the same source.  The compiler in DJGPP
is indeed a port of GCC for x86 to DOS.  But the libraries were either
written specifically for DJGPP (like most of libc.a) or adapted from
free libraries written by others (like libm.a, which originated at Sun
and was rewritten by Cygnus).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019