C Comparison Question



I had the following code on an old ARM compiler:

unsigned char *a;
unsigned char *b;

....

if (*a != (~(*b)))

and when I looked at the assembly-language, it was putting *b into a
32-bit register, complementing the entire register, then comparing
against *a which was in a second 32-bit register.

The upper 24 bits of *b were always set to 1 because they started as
0.

This wouldn't work as I intended it, because even if *a and *b were
complements, the test would fail.

Question: in the comparison above, is the compiler allowed to extend
*b to 32 bits, complement the 32 bits, extend *a to 32 bits, then
compare the two 32-bit values?

Or should the compiler be comparing only 8 bits?

Thanks, DTA
.



Relevant Pages

  • Re: Order of comparision
    ... chances are for an integer comparison you will load a register with the ... In a *strongly* typed language (and for purposes of this discussion, ... the compiler to choose between solutions. ... As for loading into a register or comparing two memory locations, ...
    (comp.lang.javascript)
  • Re: C Comparison Question
    ... unsigned char *a; ... is the compiler allowed to extend ... Or should the compiler be comparing only 8 bits? ... any operand with rank less than int ...
    (comp.lang.c)
  • Re: C Comparison Question
    ... unsigned char *a; ... 32-bit register, complementing the entire register, then comparing ...
    (comp.lang.c)
  • Re: C Comparison Question
    ... unsigned char *a; ... 32-bit register, complementing the entire register, then comparing ... Or should the compiler be comparing only 8 bits? ...
    (comp.lang.c)
  • Re: C Comparison Question
    ... unsigned char *a; ... and when I looked at the assembly-language, it was putting *b into a ... 32-bit register, complementing the entire register, then comparing ...
    (comp.lang.c)