unconstexpr icon indicating copy to clipboard operation
unconstexpr copied to clipboard

Does it support application-wide counter?

Open thorichelli opened this issue 5 years ago • 2 comments

I think, the counter starts from the first value at the beginning of each new translation unit, is it possible to use an incrementing counter application-wide? I want to have unique values between translation units either. Do you think FILE macro (converted to an int value, in compile-time) helps?

thorichelli avatar Oct 12 '20 15:10 thorichelli

Can you give me some context? Constant evaluation is always translation unit focused. If you want to make each translation unit fully independent I recommend adding an anonymous namespace in the unconstexpr headers or in your project. This will make sure that each declaration / function / etc.. is only usable inside the translation unit and will not leak its state to other ones.

DaemonSnake avatar Oct 13 '20 00:10 DaemonSnake

To access a global array by index from different TUs, I need to have a unique number even between TUs. I want to keep hit count for specified statements like the following;

A.cpp globArr[0]++; globArr[1]++; globArr[2]++; globArr[3]++;

B.cpp globArr[4]++; globArr[5]++; globArr[6]++;

Global.h int globArr[7];

The workaround is having distinct arrays for each TUs, is there another way?

thorichelli avatar Oct 13 '20 15:10 thorichelli