[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] A Question Of Optmization

From: Graham Davies
Subject: Re: [avr-gcc-list] A Question Of Optmization
Date: Wed, 16 Apr 2008 07:20:08 -0400

David Brown wrote:
In fact, the compiler will *always* do *exactly*
what your program code asks ...

Although the general thrust of your argument is correct, this statement may not be true, depending on how the reader interprets "what your program code asks". The language definition requires the compiler to produce code which *has the same final effect* as what you have written, but in the interests of optimization, it is permitted to deviate from doing each and every thing you have asked it to do. It is thinking that the compiler must do exactly what you have asked that leads people to omit the volatile keyword in the first place.

The volatile keyword tells the compiler that things happen to or are caused by a variable that would otherwise be unknown to the compiler when it translates a unit of code. This is an indication that the compiler cannot evaluate the final effect of access to that variable during the translation. Therefore, it translates each access exactly as it is written. In fact, then, you can only be sure that "the compiler will *always* do *exactly* what your program code asks" if your variables are volatile.

You are right that fiddling with optimization flags is not required to have the same effect and is not the way to fix the problem. I think the important thing here is to read the manual for your compiler as this won't be specified by the language standard.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]