Weird things often occur in programming. We can tell so-called reasons to some of them. For others, the only thing we can do is, how the hell could these be? We have to pay extra attention to avoid these in order not to fall into debugging nightmares.
10000000000000000 != 10000000000000000 ???
1 | float a = 10000000000000000.0; |
When printing them, it turns out:
1 | a = 10000000272564224.000000 |
When viewing them in Watch under Debug, it turns out:
Name | Value | Type |
---|---|---|
a | 1.0000000e+016 | float |
b | 2.7256422e+008 | float |
Reason: discussed in here.
215510*10000 != 2155100000 ???
1 | UINT64 time1 = 215510*10000; |
When printing them or in Watch, it turns out:
1 | time1 = 18446744071569684320 |
We have to use one of the following codes in order to get correct answer:
1 | UINT64 time3 = (UINT64)215510 * 10000; |
Reason: discussed in here.
3 < –1 ???
1 | int start = 3; |
When running the above code, it will run printf("In...\n");
infinitely. Although based on the condition (3<-1
) of the for
loop, it should never do this. Weird, huh?
To avoid this, you have to compute the long condition equation first, like:
1 | ... ... |
Reason: discussed in here.