C++ 64bit issue
- by Bobby
I have the following code:
tmp_data = simulated_data[index_data];
unsigned char *dem_content_buff;
dem_content_buff = new unsigned char [dem_content_buff_size];
int tmp_data;
unsigned long long tmp_64_data;
if (!(strcmp(dems[i].GetValType(), "s32")))
{
dem_content_buff[BytFldPos] = tmp_data;
dem_content_buff[BytFldPos + 1] = tmp_data >> 8;
dem_content_buff[BytFldPos + 2] = tmp_data >> 16;
dem_content_buff[BytFldPos + 3] = tmp_data >> 24;
}
if (!(strcmp(dems[i].GetValType(), "f64")))
{
dem_content_buff[BytFldPos] = tmp_data;
dem_content_buff[BytFldPos + 1] = tmp_data >> 8;
dem_content_buff[BytFldPos + 2] = tmp_data >> 16;
dem_content_buff[BytFldPos + 3] = tmp_data >> 24;
dem_content_buff[BytFldPos + 4] = tmp_data >> 32;
dem_content_buff[BytFldPos + 5] = tmp_data >> 40;
dem_content_buff[BytFldPos + 6] = tmp_data >> 48;
dem_content_buff[BytFldPos + 7] = tmp_data >> 56;
}
I am getting some weird memory errors in other places of the application when the second if statement is true and executed. When I comment out the 2nd if statement, the problem works fine. So I suspect the way I am performing bitwise operations for 64bit data is incorrect.
Can anyone see anything in this code that needs to be corrected?