This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Stupid off-topic question
- To: "'nbecker at fred dot net'" <nbecker at fred dot net>, gcc at gcc dot gnu dot org
- Subject: RE: Stupid off-topic question
- From: Anjul Srivastava <anjul dot srivastava at sanchez dot com>
- Date: Wed, 2 Aug 2000 15:09:16 -0400
Maybe this will help you understand why gcc is correct.
main()
{
signed int x;
unsigned int y;
unsigned int z;
x=-1;
y=x;
z=y%4083;
printf("%u\n",y);
printf("%u\n",z);
printf("%u\n",4083*(y/4083)+z);
}
Output:
4294967295
2433
4294967295
-----Original Message-----
From: nbecker@fred.net [mailto:nbecker@fred.net]
Sent: Wednesday, August 02, 2000 2:00 PM
To: gcc@gcc.gnu.org
Subject: Stupid off-topic question
I can't understand this logic.
-1 % 4083 -> -1
But
-1 % (unsigned)4083 -> 2433.
I would expect by any reasonable mathematical definition, that
-1 % 4083 -> 4082.
This was gcc-2.95.2 i686-pc-linux-gnu.
If the generated code is really that stupid, maybe gcc should give a
warning?