This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Abusive (?) promotions to int
- From: Andreas Schwab <schwab at suse dot de>
- To: Alexandre Courbot <Alexandre dot Courbot at lifl dot fr>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 24 Sep 2003 12:15:59 +0200
- Subject: Re: Abusive (?) promotions to int
- References: <200309241200.55125.Alexandre.Courbot@lifl.fr>
Alexandre Courbot <Alexandre.Courbot@lifl.fr> writes:
> Hello everybody,
>
> I've been looking for macros to control integer promotions, especially for
> temporary statements. Consider for instance the following code:
>
> char c;
> ...
> if (c + 4 > 10) ...
>
> On my target, c gets zero_extended to int, then the addition and comparison
> are performed in SImode, while it is not really necessary (could be done in
> QImode as well and would save the zero_extend).
No, it cannot. You would get wrong behaviour if c >= 252 (assuming char
is unsigned 8 bit), because (char)(c + 4) < 10, but c + 4 > 10.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."