Mail Archives: djgpp/1992/09/30/14:57:49
> ABS works better as a macro -- then the compiler can determine type
> dynamically.
>
> #define ABS(x) ((x) < 0 ? -x : x)
>
> should work, unless I'm missing some obscure ANSI type promotion problem. If
> you want to get fancy, you can use typeof with GCC to coerce 0 to the proper
> type, but I'm not at all sure it's necessary.
It shouldn't be necessary. But you should enclose ALL the x's in
parentheses, and you this will still evaluate x twice if it's an
expression.
--
Eric Backus
ericb%hplsla AT hplabs DOT hp DOT com
(206) 335-2495
- Raw text -