regarding type promotion

Richard Harvey Chapman hchapman-gcc-help@3gfp.com
Tue Aug 19 22:36:00 GMT 2008


I should have included the program source.

H.


hchapman@anthrax:~$ cat a.c
#include <stdio.h>

int main()
{
  unsigned int value = 1;
#define BITSET 0x1234

  // Wrong: always true if value is odd since BITSET == BITSET is 
evaluated first
  if (value & BITSET == BITSET)
  {
    printf("One\n");
  }

  // Right:
  if ((value & BITSET) == BITSET)
  {
    printf("Two\n");
  }

  return(0);
}



More information about the Gcc-help mailing list