简体   繁体   中英

Running a program on a 64bit and 32bit system

Is there any reason why a c++ program that runs perfectly on a 64 bit system crashes on a 32 bit system? I have a program tested on 2 servers. one a 64bit and other 32bit. The program doesnt have bit specific commands. Initially it was working in both until i made a chage and added a structure and called it. The program crashed when this structure object was called for the first time. But if i print the value of the elements 1 line before the crash it, the values are there. Btw, the by value i mean integers and no pointers or other funny stuff. I tried initiating these integers as uint32_t and such experiments. But to meet a dead end.

the structure is like this

struct info {
    int id1, id2;
    string test;
};

map<string, info> allInfo
vector<string> temp;
/* temp populated */

info details = {atoi(temp[0].c_str()),atoi(temp[2].c_str()),temp[3].c_str()};
allInfo[temp[1].c_str()] = details; 

/*somewhere after this it is accessed */

map<string, info>::iterator i;
/* printing the values here seems ok.. */
cout << (*i).second.id1 << endl << (*i).second.id2 << endl;
string first_id = "idOne : " + (*i).second.id1; 
string second_id = "idTwo: " + (*i).second.id2;

一个简单的原因是未定义的行为。

Just a guess. Did you compile it on/for 64bit machines? It may be that there is some opcode in there that is not available in 32bit machines.

So no cast, no dynamic allocation and a crash in 32 bit build and not in 64 bit build. My first guess would be accessing an array outside their range.

There's multiple things that could go wrong, and without a debugger it's going to be a nightmare to find out.

Option 1: Convince whoever has admin rights to the server to install gdb .

Option 2: Add print statements everywhere to figure out exactly which line the segfault occurs on a post it here (or try and figure it out from that on your own).

you're adding integers to char-arrays in:

string first_id = "idOne : " + (*i).second.id1; 
string second_id = "idTwo: " + (*i).second.id2;

may be you're test-sets differs and on the non-throwing system you accidently get a valid address to assign to the string variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM