A bitmap sort programme,in which the assign part is:
for(i = MAX/64-1;i >= 0;i--){
for(j = 0;j < 64;j++){
if(0 != (arr[i] & (1 << j))){
*p++ = j + 64 * i;
}
}
}
I gdb it,sometimes when the if condition returns 0 and the program still enter the block and execute the statement:
*p++ = j + 64 *i;
which cause segmentfault at last,I just don’t understand under which circumstance would it happen
example:
when gdb status like this:
j=44, i=6250, arr[i]=4096 and print (arr[i] & (1 << j)) gives 0
but programme still enter the block
My guess is that you have 32 bit ints but your array data type is
int64_t. In which case you need to change:to:
since
1 << jis undefined forj >= sizeof(int) * CHAR_BIT(i.e.j >= 32in your case).