Is it possible to #DEFINE a Comparison Operator?

I have a comparison operator hidden away in some code that I'd like to be able to quickly change along with some other #DEFINE'd items.

However using (for example)

int const operator = >


#DEFINE operator >

do not appear to work.


‘operator’ is a reserved C++ keyword.

Edit: For a complete list of C++ keywords see

Yes I don’t make these ‘links’ as I want people to see where they are being sent to!

#define op(x, y)  ((x) > (y))

Is the usual way to accomplish this. You use "op" in your code similar to a function call.

a = op(3, x);


if (op(i,10))

Then you can just change the definition of op when you want to change the operator.

Another possible way to do this would be to replace the comparison operator in question with a unique symbol (eg COMP or FRABULATE). Then you can #define the symbol to be the operator you want.

#define COMP   > 

if (a COMP b)
{ ...

I would not try to redefine ">" itself as that would mess up a bunch of other things.

Thanks guys, that helps a lot.

Have made the suggested changes and the code is a good 'un :)