This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: regarding type promotion


Bob Plantz wrote:
Another rule I gave them is "multiplication and division have higher
precedence than addition and subtraction; use parentheses in all other
cases."
++

I used to always get tripped up in embedded code because "==" has
precedence over "&" which I do not believe is intuitive to most people.

unsigned int value;
#define BITSET 0x1234

// Wrong: always true if value is odd since BITSET == BITSET is
evaluated first
//        which reduces to "(value & 1)"
if (value & BITSET == BITSET) {} // Bits are set

// Right:
if ((value & BITSET) == BITSET) {} // Bits are set



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]