Boolean comparison of dereferenced int* and int failing in C
I'm writing a program in C on Debian Linux x64. In part of the code, I have the following if statement:
if (*all_drops >= (npes * 128)) {
break;
}
all_drops
is an int*
which has been assigned an int
's worth of memory, while npes
is an int
with the value 2. Therefore, the if statement should be true when the value in all_drops
is at least 256. However, I've had the variable get above 1000 without the if statement evaluating true.
I'm not sure if there's some nuance in comparing dereferenced pointers to other numbers, but I've searched Google and haven't been able to find any similar issues (which leads me to believe I am missing something). Any help you could g开发者_Python百科ive would be greatly appreciated.
This works as intented: http://ideone.com/DjHGI
I guess the problem can be in the way you're initializing *all_drops
精彩评论