I recently had a bug that took me a while to track down.
I had the time as UNIX time (32bit variable) and needed to get rid of the date part so I did time %= oneDay with oneDay defined as 24*60*60.
All good. However, I needed to keep the original variable so changed to dayTime = time % oneDay. Same thing, yes?
Anyone see the problem yet?
The problem is with the time % oneDay assignment.
After the preprocessor has run the expression gets expanded to, time % 24*60*60 and as % and * have the same precedence the % get carried out first to give a completely wrong result.
I got around this by changing to #define oneDay (24*60*60).
Still learning.
Mike.
I had the time as UNIX time (32bit variable) and needed to get rid of the date part so I did time %= oneDay with oneDay defined as 24*60*60.
All good. However, I needed to keep the original variable so changed to dayTime = time % oneDay. Same thing, yes?
Anyone see the problem yet?
The problem is with the time % oneDay assignment.
After the preprocessor has run the expression gets expanded to, time % 24*60*60 and as % and * have the same precedence the % get carried out first to give a completely wrong result.
I got around this by changing to #define oneDay (24*60*60).
Still learning.
Mike.