If you just need that for integer constants (type int
) you may use enumerations for this type of constants
enum { SUM_A_B = (VALUE_A + VALUE_B), };
possible advantages:
- the sum is only evaluated once by the compiler. This is not a big
deal for modern compilers if this is only such a simple sum, but
could make a small difference when you are using more complicated
expressions
- even nowadays compiler errors and debugging information isn't that
good for values coming from the preprocessor. Enumeration constants usually can be traced well.
A disadvantage is that the value itself is not accessible in the preprocessor itself. So you can't do #if/#else
constructs with it. But you could at least still define it as
#define SUM_A_B SUM_A_B
So #ifdef/#else
constructs would still work.