home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16988 < prev    next >
Encoding:
Internet Message Format  |  1992-11-22  |  1.0 KB

  1. Path: sparky!uunet!mcsun!news.funet.fi!hydra!klaava!wirzeniu
  2. From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: the abs() function in C
  5. Message-ID: <1992Nov22.140228.15739@klaava.Helsinki.FI>
  6. Date: 22 Nov 92 14:02:28 GMT
  7. References: <pebi.722223424@zephyr.aem.umn.edu> <1992Nov22.022357.20377@waggen.twuug.com>
  8. Organization: University of Helsinki
  9. Lines: 20
  10.  
  11. alpha@waggen.twuug.com (Joe Wright) writes:
  12. >This is almost always a macro like:
  13. >
  14. >#define abs(x) ((x)>=0 ? (x) : -(x))
  15.  
  16. It may be true that most systems define abs as a macro (I don't have
  17. enough experience with different systems to know), but the above way
  18. is not a good way for a standard conforming system, since it evaluates
  19. its arguments multiple times.
  20.  
  21. >Look around.  Maybe you can simply declare it ..
  22. >
  23. >    extern int abs();
  24.  
  25. Or preferably by including <stdlib.h> (although it doesn't work on
  26. non-standard systems, of course).
  27.  
  28. --
  29. Lars.Wirzenius@helsinki.fi  (finger wirzeniu@klaava.helsinki.fi)
  30.    MS-DOS, you can't live with it, you can live without it.
  31.