Since you're using GCC and you say that making the variable volatile
does not work, you can trick the optimizer into thinking that the loop changes the variable by lying to the compiler:
while(global)
asm volatile("" : "+g"(global));
This is an inline assembly statement which says that it modifies the variable (it's passed as an input-output operand). But it's empty, so obviously it doesn't do anything at runtime. Still, the optimizer thinks it modifies the variable - the programmers said so, and the compiler, barring operand substitution (which means simply replacing one text with another), doesn't really care about the body of inline assembly and won't do any funny things to it.
And because the body is empty and the constraint used it the most generic one available, it should work reliably on all platforms where GCC supports inline assembly.