Wednesday, August 15, 2007

GCC Operators (C++)

Min/Max gcc operators:

Note: "< ?", "> ?", "< ?=", and "> ?=" should have not any spaces.


"< ? and > ? and the min and max operators"

The concept with the min and max operators is that they return an expression that is the minimum or the maximum value of two operands. Therefore, instead of doing something like:

x > y ? y : x; OR x > y ? x : y;

You can now do:

"x < ? y; OR x > ? y;"

Also, you can chain these operands out:

"x < ? y < ? z < ? a < ? b < ? c;"

This is helpful when you need to find the minimum value of multiple values.

Also, there is something called min-assingment and max-assignment gcc operators.
Something in code that corresponds to:
"Set x to the minimum of y and z" OR "Set x to the minimum of x and y"

x = ( z < y ? z : y );
x = ( x < y ? x : y );
Alternatively:
"x = z < ? y;"
"x = x < ? y;"

Now, something of the form ?= is valid. Therefore, the above would look like:

"x < ?= y; // for x = x < ? y;"
"x = (z < ? y);"

Note, you can mix everything together. The reason that this is important is because that it doesn't compute anything more than once.

No comments: