Will an empty for loop used as a sleep be optimized away?

c

Solution

You're at the mercy of the compiler. Indeed if it's smart it will detect it's a noop. Incidentally, Neil Butterworth has a nice post where he also touches on this subject.

Problem

I am looking over some code to review and have come across a busy wait as such: ``` int loop = us*32; int x; for(x = 0;x<loop;x++) { /*do nothing*/ } ``` I seem to recall reading that these empty loops can be optimized away. Is this what would happen here or can this work?

Original source

Related problems