This question is strictly related to the C or C++ language capabilities. I don't recommend the code below as a design pattern. I don't use it and I don't encourage it. But I'm just curious to improve my knowledge!
I have a define that contains a label and a goto condition.
#define BROP(num, sum) \
num = rand_lcg(generated); \
if (num % 2) \
{ \
rng1: \
generated = rand_lcg(generated); \
if (generated < 512) \
sum -= generated; \
else \
goto rng1; \
}
And later in the code I use it like this:
for (i = 0; i < iterations; i++)
{
BROP(num, sum);
BROP(num, sum);
BROP(num, sum);
// ...
}
I end up in a situation where the loop gets unrolled and the label gets redefined.
Is there a smart construct I can use to make the compiler rename the label each time the define is "instantiated"?
I know of ALL the alternatives of avoiding this statement but still, I don't know the answer to the question.