From 0ae6ab57aef8984e4e01ba8171456b2a22a2a31f Mon Sep 17 00:00:00 2001 From: cuz Date: Tue, 4 Mar 2003 11:02:11 +0000 Subject: [PATCH] Last fix was wrong git-svn-id: svn://svn.cc65.org/cc65/trunk@1999 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/typecast.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/cc65/typecast.c b/src/cc65/typecast.c index ab410f668..7e0c36df8 100644 --- a/src/cc65/typecast.c +++ b/src/cc65/typecast.c @@ -144,27 +144,20 @@ int TypeCast (ExprDesc* lval) unsigned OldBits = OldSize * 8; unsigned NewBits = NewSize * 8; - /* Remember if the old value was negative */ - int Negative = (lval->ConstVal & (0x01UL << (OldBits-1))) != 0UL; - - /* Check if the new datatype will have a smaller range */ + /* Check if the new datatype will have a smaller range. If it + * has a larger range, things are ok, since the value is + * internally already represented by a long. + */ if (NewBits <= OldBits) { /* Cut the value to the new size */ lval->ConstVal &= (0xFFFFFFFFUL >> (32 - NewBits)); - /* If the new type is signed and negative, sign extend the - * value - */ - if (Negative && !IsSignUnsigned (NewType)) { - lval->ConstVal |= ((~0L) << NewBits); - } - - } else { - - /* Sign extend the value if needed */ - if (Negative && !IsSignUnsigned (OldType) && !IsSignUnsigned (NewType)) { - lval->ConstVal |= ((~0L) << OldBits); + /* If the new type is signed, sign extend the value */ + if (!IsSignUnsigned (NewType)) { + if (lval->ConstVal & (0x01UL << (NewBits-1))) { + lval->ConstVal |= ((~0L) << NewBits); + } } } -- 2.39.5