The GNU compiler provides these extensions to the C++ language (and you
can also use most of the C language extensions in your C++ programs). If you
want to write code that checks whether these features are available, you can
test for the GNU compiler the same way as for C programs: check for a
predefined macro __GNUC__. You can also use __GNUG__ to
test specifically for GNU C++ ().
7.1. Minimum and Maximum Operators in C++
It is very convenient to have operators which return the "minimum" or the
"maximum" of two arguments. In GNU C++ (but not in GNU C),
- a <? b
is the minimum, returning the smaller of the numeric values
a and b;
- a >? b
is the maximum, returning the larger of the numeric values a
These operations are not primitive in ordinary C++, since you can
use a macro to return the minimum of two things in C++, as in the
#define MIN(X,Y) ((X) < (Y) ? : (X) : (Y))
You might then use int min = MIN (i, j); to set min to
the minimum value of variables i and j.
However, side effects in X or Y may cause unintended
behavior. For example, MIN (i++, j++) will fail, incrementing
the smaller counter twice. The GNU C typeof extension allows you
to write safe macros that avoid this kind of problem (Section 6.6 Referring to a Type with typeof).
However, writing MIN and MAX as macros also forces you to
use function-call notation for a fundamental arithmetic operation.
Using GNU C++ extensions, you can write int min = i <? j;
Since <? and >? are built into the compiler, they properly
handle expressions with side-effects; int min = i++ <? j++;