[prog] wierd C++ operator

Cliff Crawford cjc26 at cornell.edu
Wed May 28 10:03:35 EST 2003


On Tue, 27 May 2003, Jimen Ching wrote:
>Of course, I don't see why you can't get the same behavior with:
>
>        result = whatever < 1000 ? 1000 : whatever;
>
>Perhaps the GNU people think
>
>        result = 1000 <? whatever;
>
>is less code to write and thus, is better or something.

The GNU version also only evaluates its arguments once (according to
the info page for gcc).  So the two would have different behavior if
instead of using a constant, you called a function with side-effects
to find the minimum value:

	result = whatever < min_val() ? whatever : min_val();
vs.
	result = min_val() <? whatever;

Of course, you could just cache the return value of min_val() in a
variable, so it's not really a problem to use the standard C version.


More information about the Programming mailing list