From: Eric Backus Subject: Re: abs()olutely hopeless? To: djgpp AT sun DOT soe DOT clarkson DOT edu (djgpp) Date: Wed, 30 Sep 92 14:29:30 PDT Mailer: Elm [revision: 66.25] > >#define ABS(x) ((x) < 0 ? -(x) : (x)) > >so that e.g. ABS(-a+b) works correctly. > > Should that not actually be: > > #define ABS(x) \ > ({typedef _tx = (x); \ > _tx _x = (x); \ > _x < 0 ? -_x : _x; }) > > This yields the correct result when you do: > foo = abs(bar += 17); Yes, this is better, but it is a GNU-cc-only extension to the C language. The non-typedef solution is pure ANSI C. -- Eric Backus ericb%hplsla AT hplabs DOT hp DOT com (206) 335-2495