ich lerne derzeit C-Programm aber stieß ich auf einige seltsame Verhalten ich erwartet hatte ein Ergebnis, aber zwei Ergebnisse ist wie diese könnte Wie können sowohl (i + 1) <ii als auch (i + 1)> ii beide wahr sein?
$ ./a.out
yes1 0x80000000
yes3 0x80000000
gedruckt, wie das möglich?
Ich kann das Ergebnis nicht verstehen.
OS : x86_64 Ubuntu Linux
C compiler : gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
gcc -O2 weird.c
#include <stdio.h>
int main() {
int i = 0x7fffffff;
int ii = 0x0000000f;
if ((i + 1) < ii)
printf ("yes1 %#x\n", i + 1);
if ((i + 1) == ii)
printf ("yes2 %#x\n", i + 1);
if ((i + 1) > ii)
printf ("yes3 %#x\n", i + 1);
return 0;
}
0x7fffffff + 1 = 0x80000000 –
gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7 .2 macht es richtig (auf einem 32-Bit-System) – fritzone
Es wurde entfernt, aber Sie hatten ursprünglich das C++ - Tag, kümmern Sie sich überhaupt um C++? –