Francisco Silva <fran...@gmail.com> wrote: > Try the following spell: > ------------------ > #define FLAG_A 0x01 > #define FLAG_B 0x02 > ... > uint8_t t /* temporary dummy variable */ > if ((t = flags & FLAG_A)) ... > if ((t = flags & FLAG_B)) ... > ------------------ > The double parenteses avoids a ggc warning.
Using a typecast looks a little better, I think. Also, I noticed it can help to use inline functions to encapsulate tests, as this helps the compiler finding out there are no side effects of reducing the operation to 8 bits. Andrew, maybe you can post some compilable code snippet to check. I tried creating a small piece of code myself, but GCC always compiled that one using plain 8-bit instructions. That all depends a little on the context, it seems. Technically, the compiler is required to perform an implied promotion to 16 bits, and it is then only allowed to reduce the operation to just 8 bits if the compiler can be entirely sure this behaves the same as the operation with everything promoted to `int'. So in case of doubt, the compiler will always be on the safe side to use 16 bits, because standard conformity must be the primary goal, and optimization only comes next. -- cheers, J"org .-.-. --... ...-- -.. . DL8DTL http://www.sax.de/~joerg/ NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-) _______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list