Help with function

Karl Heuer karl at haddock.ima.isc.com
Sat Jan 20 07:17:50 AEST 1990


In article <3477 at cbnewsj.ATT.COM> veenu at cbnewsj.ATT.COM (veenu.r.rashid,mt,) writes:
>As it turns out, the abs() macro definition tends to return int, (but not
>always!), while fabs() returns the correct floating point value.  Now, is
>this just a macro characteristic or is it the compiler I'm using.

|abs| is a standard library function that expects an |int| and returns an
|int|.  I don't know anything about the macro definition on your machine, and
neither should you, if you're interested in writing portable programs.
Passing it a non-|int| value is undefined behavior; all bets are off.

Karl W. Z. Heuer (karl at haddock.isc.com or ima!haddock!karl), The Walking Lint
________
I'm assuming you have a sane implementation.  If |abs| is defined as
	#define abs(x) ((x) < 0 ? -(x) : (x))
then you should file a bug report, since it will break code like |abs(*p++)|.



More information about the Comp.lang.c mailing list