David Kastrup
3/15/2007 3:50:00 PM
Tim Hunter <rmagick@gmail.com> writes:
> John Joyce wrote:
> > one of the less lovely things to read in C like languages, but after
>> you get used to it, it is actally a space saver.
>> It is relly just an conditional with two possible outcomes
>
> In C the ?: operator is useful when writing macros since it's an
> expression, as opposed to if/then, which is a statement. (Unlike
> Ruby.) The ?: operator has been terribly abused, though, by people
> who believe that you can make a program run faster by taking out
> whitespace.
In effect, you are saying that ?: is the wrong way to fix a defect in
the language.
By the way, you can do something like
#include <stdio.h>
#define abs(x) ({typeof(x) _x = x; if (_x<0) _x = -_x; _x;})
int main() {
printf("%d %f\n", abs(5), abs(-7.3));
return 0;
}
with GCC (the obvious simplification using if/else as the last thing
in the block does _not_ work, however).
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum