You could do it the other way around:
Note: Just noticed Daniel Fischer's comment, which suggests exactly the same, before me.
#define ITEMS_PLUS_ONE 5
#define ITEMS (ITEMS_PLUS_ONE - 1)
The issue is that the preprocessor doesn't do math. It only does copy&paste.
When you write #define ITEMS_PLUS_ONE (ITEMS + 1)
, unroll
is replaced with (4 + 1)
, not with 5
.
Once this reaches the compiler, it doesn't matter. Even without optimization, the calculation is done during compilation, and (4 + 1)
is exactly the same as 5
.
But in your compiler, #pragma unroll
is processed before compilation, and wants the simple number.