While sounding nonsensical.....
I want a Constant where every time you use it it will increment by 1
int x;
int y;
x = INCREMENTING_CONSTANT;
y = INCREMENTING_CONSTANT;
where x == 1; and y == 2
Note I don't want y = INCREMENTING_CONSTANT+1 type solutions.
Basically I want to use it as a compile time unique ID ( generally it wouldn't be used in code like the example but inside another macro)
The increment operator obviously cannot applied for a const (ant) variable, because the const keyword prevents it to be changed after the initial definition. That's why the compiler error is issued.
If so, it's an easy fix: just remove the incrementing statement that runs at the end of every loop iteration. That way you're left with only the one increment line in the if statement. By the way, do note that there's no point in using a for loop that only ever has one iteration.
If you just need something unique ID ish, can you use the __LINE__
preprocessor symbol? It's not what you're asking for, but it might work for your purposes.
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