[lug] OT: cc question

Alisdair Davey ard at pergamentum.com
Wed Dec 3 10:57:30 MST 2003


On Wed, 2003-12-03 at 09:43, Scott Herod wrote:
> On Wed, 3 Dec 2003, Stephen Queen wrote:
 
C prog deleted ....

> So others have suggested that you should load the math library.  A more
> interesting question is why you don't have to do so when you compile with
> optimization.  I suspect that if you dig around though the header files in
> /usr/include you will find that the sqrt() call is inlined.

I "discovered" this feature a few weeks ago when restoring some old code
from backup. In order to answer the "but why?" question for myself I did
a little digging. Scott is correct about the inlining. If you compile
with 
  gcc -O2 -fno-inline
you need to include -lm to use the sqrt() call. When you compile with
-O2, __USE_EXTERN_INLINES gets set, which includes the inline header
file,  bits/mathinline.h. In here you'll find all kinds of opaque
goodies! 
Cheers
Alisdair


-- 
Dr Alisdair Davey                                 ard at pergamentum.com
Pergamentum Solutions                             Tel: 1-303-554-9190
2066 Dailey Ln
Superior, CO 80027




More information about the LUG mailing list