This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: unsigned / double propagation weirdness?
- From: Falk Hueffner <falk dot hueffner at student dot uni-tuebingen dot de>
- To: Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: 23 Feb 2004 16:55:11 +0100
- Subject: Re: unsigned / double propagation weirdness?
- References: <403A116B.6080300@tat.physik.uni-tuebingen.de>
Richard Guenther <rguenth@tat.physik.uni-tuebingen.de> writes:
> Hi, I'm getting confusing (but consistent along a lot of different
> compilers) results out of this testcase:
>
>
> int main(int argc, char **argv)
> {
> double dm = 1.0;
> unsigned int i = 1;
> if (-i*dm != -((double)i)*dm)
> abort();
> return 0;
> }
>
> From the standard I cannot understand why this should abort.
The point is that "-i" is still an unsigned number. "-i" basically
means "~i + 1", so it's something largish, but not someting negative.
Another cute instance is:
int a[10];
int *b = a+1;
unsigned i = 1;
return b[-i];
This works on 32 bit platforms and crashes on 64 bit platforms.
A while ago I proposed generally warning about negation of unsigned
entities, but there were a few objections, and I never got around to
finishing it.
--
Falk