[lug] OT: cc question

Ed Hill ed at eh3.com
Wed Dec 3 10:26:17 MST 2003


On Wed, 2003-12-03 at 11:43, Scott Herod wrote:
> > This is true on debian and slackware. Does anyone know of an explaination?
> 
> 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.


For fun, try:

  cc -c simple.c
  nm simple.o

and then compare it with:

  cc -O3 -c simple.c
  nm simple.o

where, in the latter case, you'll see that the compiler was smart enough
to remove the sqrt() function call since its argument was a constant and
thus the return value could be computed at compile time.

Ed

-- 
Edward H. Hill III, PhD
office:  MIT Dept. of EAPS;  Room 54-1424;  77 Massachusetts Ave.
            Cambridge, MA 02139-4307
email:   eh3 at mit.edu,  ed at eh3.com
URL:     http://web.mit.edu/eh3/
phone:   617-253-0098
fax:     617-253-4464
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20031203/287ab799/attachment.pgp>


More information about the LUG mailing list