I want to have a C preprocessor macro that knows the number of instantiations/macro calls of this macro so far. Example:
int main() {
printf("%d\n", MACRO());
printf("%d\n", MACRO());
}
Should print
0
1
Is something like this possible?
Note that it is not enough to forward this to a function as proposed below. It should work in the following context:
// global variable
std::vector<bool> calls_hit;
#define OTHER_MACRO() \
{ \
const int counter = MACRO(); \
calls_hit.resize(std::max(calls_hit.size(), counter)); \
calls_hit[counter] = true; \
}