This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: unsigned / double propagation weirdness?


Falk Hueffner wrote:
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.

Warning about such would be indeed very useful. We even warn about signed/unsigned comparisons, so there is precedent.

Richard.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]