J
junky_fellow
Hi,
Consider the following piece of code:
int main(void)
{
volatile int i;
volatile int k;
i=100; /* line 1 */
k=200; /* line 2 */
i=300; /* line 3 */
k=400; /* line 4 */
return 0;
}
I want to know if the compiler can reorder any of the lines 1 to 4 ?
I believe that, the line 3 will always be executed after line 1, as
'i' is volatile and compiler will not do any optimization on 'i".
Similary, line 4 will always be executed after line 2.
However, line 2 may be executed before line 1 and line 3 may be
executed before line 2.
Similarly, line 4 may be executed before line 3.
Please let me know if my assumption is correct or not ?
thanks a lot for any help ...
Consider the following piece of code:
int main(void)
{
volatile int i;
volatile int k;
i=100; /* line 1 */
k=200; /* line 2 */
i=300; /* line 3 */
k=400; /* line 4 */
return 0;
}
I want to know if the compiler can reorder any of the lines 1 to 4 ?
I believe that, the line 3 will always be executed after line 1, as
'i' is volatile and compiler will not do any optimization on 'i".
Similary, line 4 will always be executed after line 2.
However, line 2 may be executed before line 1 and line 3 may be
executed before line 2.
Similarly, line 4 may be executed before line 3.
Please let me know if my assumption is correct or not ?
thanks a lot for any help ...