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