avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] compiler bug?


From: Graham Davies
Subject: Re: [avr-gcc-list] compiler bug?
Date: Tue, 10 Feb 2009 09:08:59 -0500

Richard F wrote:
[in] rtc.time_element.tm_wday = (rtc.time_element.tm_wday < 6) ? rtc.time_element.tm_wday++ : 0;
... the expression rtc.tm_wday++ doesn't appear to be evaluated.

If the conditional expression evaluates TRUE, the statement reduces to this:
rtc.time_element.tm_wday = rtc.time_element.tm_wday++;

The C language is defined such that the RHS will be evaluated completely before assignment to the variable on the left. So what happens is that the value of rtc.time_element.tm_wday is retrieved and stored, rtc.time_element.tm_wday is then incremented and, finally, the stored value (the original value of rtc.time_element.tm_wday) is assigned to rtc.time_element.tm_wday (wiping out the increment). The compiler is at liberty to optimize away the redundant increment (unless rtc.time_element.tm_wday is declared volatile, in which case it would be incremented and then put back where it was).

Graham.






reply via email to

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