Mail Archives: djgpp/1992/09/30/17:53:40
> >#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
- Raw text -