I would like to use some previously defined constants in the definition of a new constant, but my C compiler doesn't like it:
const int a = 1;
const int b = 2;
const int c = a; // error: initializer element is not constant
const int sum = (a + b); // error: initializer element is not constant
Is there a way to define a constant using the values of other constants? If not, what is the reason for this behavior?
Const vars can't be defined as an expression.
#define A (1)
#define B (2)
#define C (A + B)
const int a = A;
const int b = B;
const int c = C;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With