On 7/13/06, Jeff Griglack <grigl...@gmail.com> wrote:
The compiler should be smart enough that it doesn't need us to make things
simpler for it. The important point is readability so the next person who
has to maintain the code is able to figure out what is going on. Heck, I
might have to come back to my own code 6 months to a year later and want to
make it so I can quickly understand it again.
One minor point, though. If you write your macro as:
#define P5_ALARM_ENABLE (1<<5)
then the precompiler is going to put the "(1<< 5) into your code which is
going to put a 1 into a register and then shift it over before it even
applies the mask, an operation that is going to take several cycles. I
would think it would be better if you defined things with your "or" case:
#define P5_ALARM_ENABLE (0x20)
which should execute more efficiently. Or is the optimizer smart enough to
recognize this too? I don't know, I haven't looked at the code that these
would generate.
I use the "#define FLAG (x<<y)" notation as well and optimizer is
smart enough to recognize that a basic operation on a constant results
in a constant.