RFC: #pragma optimization_level
E. Weddington
ericw@evcohs.com
Fri Apr 1 23:12:00 GMT 2005
Joe Buck wrote:
>Georg Bauhaus <bauhaus@futureapps.de> writes:
>
>
>>| A busy-loop function is used to effect a delay, not too precise,
>>| but portably. Like
>>|
>>| #define COUNT 1000
>>|
>>| void f() {
>>| /*volatile*/ /*register*/ int i;
>>|
>>| for (i = 0; i < COUNT; ++i)
>>| ;
>>
>>
>Unfortunately, where there is a good argument for not using empty loops
>as busy-waits, at one time it was documented GCC behavior that it would
>work, so we can't really blame the users for trusting the doc.
>
>That's not to say that it was ever a good idea, because of the lack of
>control. If you need a precisely timed busy-wait, an inline assembly
>construct is the best bet.
>
>
>
Yeah, but that just raises the "barrier for entry" for a lot of people
starting out in e.g. embedded programming. It's much easier to throw
together a do-nothing for loop in C then it is to try and wade through
understanding how to do GCC inline assembly. Would it be reasonable to
implement what Georg wants iff volatile and register are used, even if
it has to be restricted to the C99 construct?:
for(register volatile int i = 0; i < COUNT; ++i);
I know it's terribly inaccurate as a delay, and it should be
discouraged, but unfortunately it seems to be a common idiom in embedded
code.
Thanks
Eric
More information about the Gcc
mailing list