gcc 2.95.3/ARM problems comparing with negative

Richard Earnshaw rearnsha@gcc.gnu.org
Mon Nov 1 11:59:00 GMT 2004


On Mon, 2004-11-01 at 11:47, Toralf Lund wrote:
> Richard Earnshaw wrote:
> >  So I suspect your
> >problem is the type of one of your arguments, most likely the
> >declaration of position itself.
> >  
> >
> No, position is all right. But now that you mention it, ZSTP_MAX_POS is 
> actually set up via an indirect definition involving "sizeof", following 
> a recent update. I guess that makes ZSTP_MAX_POS an unsigned, and if I 
> use an "int" typecast, I do get the correct code. I still don't quite 
> get it, though. Shouldn't -ZSTP_MAX_POS implicitly be treated as a 
> signed in any case? I would at least expect either fully signed or fully 
> unsigned operation; the actual code here seems to be a mixture of bot.

Negation of an unsigned constant produces an unsigned constant.  The
rules for unsigned arithmetic are precise and work on operations being
done modulo the 2^bit-size of the data type (unsigned int in this case):
so -X on an unsigned type is in effect (2^32 - X) on ARM.  On top of
this, the rules for a combination of signed and unsigned of the same
bit-size are that the operands are all converted to unsigned first.

R.

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com



More information about the crossgcc mailing list