[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] compiler bug?
From: |
Oleksandr Redchuk |
Subject: |
Re: [avr-gcc-list] compiler bug? |
Date: |
Tue, 10 Feb 2009 14:07:55 +0200 |
2009/2/10 Richard F <address@hidden>:
> Call me a newbie, but is there anything wrong with the following statement?
>
> rtc.time_element.tm_wday = (rtc.time_element.tm_wday < 6) ?
> rtc.time_element.tm_wday++ : 0;
"Undefined Behavior"
Try to compile this source with all warnings enabled ( -Wall switch)
Something like
warning: operation on 'rtc.time_element.tm_wday' may be undefined
should appear.
Use pre-increment.
rtc.time_element.tm_wday = (rtc.time_element.tm_wday < 6) ?
++rtc.time_element.tm_wday : 0;
But on my taste
if( ++rtc.time_element.tm_wday >= 6 ) rtc.time_element.tm_wday = 0;
is better solution (generates smaller code)
--
wbr,
ReAl