Context
Imagine some code correctness depends on some value adding or subtracting to some other, so that at compilation time one can know if compilation should be aborted.
For example :
some.h
#define A 100
#define B 20
#define C 120
Imagine that code in some.c
assumes that A+B == C
, else it does not even make sense to compile it.
Wish
We wish compilation of some.c
to fail if A+B
is not equal to C
.
some.cpp
#include "some.h"
#define CONTROL ((A)+(B)-(C))
something_that_cause_compilation_failure_if_argument_is_non_zero(CONTROL)
Non-solutions
This does not work because preprocessor does not do arithmetic, only string substitution:
#if CONTROL
#else
#error MISMATCH
#endif