C Comparison Question
- From: David T. Ashley <dashley@xxxxxxxxx>
- Date: Thu, 17 May 2012 17:48:02 -0400
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
.
- Follow-Ups:
- Re: C Comparison Question
- From: Tim Rentsch
- Re: C Comparison Question
- From: Heinrich Wolf
- Re: C Comparison Question
- From: Eric Sosman
- Re: C Comparison Question
- From: Kaz Kylheku
- Re: C Comparison Question
- From: Barry Schwarz
- Re: C Comparison Question
- From: James Kuyper
- Re: C Comparison Question
- From: Lanarcam
- Re: C Comparison Question
- Prev by Date: Re: working with big numbers
- Next by Date: Re: Possible occurrences of "char [3]"
- Previous by thread: What is the aim of making define not to have value?
- Next by thread: Re: C Comparison Question
- Index(es):
Relevant Pages
|