开发者

Variable initialisation not happening everywhere on certain platforms

I have a program that I built for RHEL5 32 bit and ubuntu10 64 bit (c++ qt4.6). When I run the program on ubuntu, all the variables are initialized without me needing to code this initialization. But When I run the program on RHEL, some of the variables are not initialized, I have noticed that they are mostly integer type and the typicial values are around 154280152. The funny thing is that it just happens in a few classes. How can this be?

update: here is a snippet of code, it is the header of one of the classes where this is happening(sorry for the layout I am looking into that right now):

#ifndef FCP_CONFIG_H

#define FCP_CONFIG_H

#include "ui_fcpConfig.h" #include

#include "fpsengine.h"

#include "fcp_cfg_delegate.h"

#define SET_COL 3

#define GLOBAL_KEY_COL 2

#define LOCAL_KEY_COL 1

#define ENABLE_COL 0

namespace Ui

{

class fcpConfig;

}

class fcpConfig : public QWidget  
{  
Q_OBJECT  

public:  
fcpConfig(QWidget *parent, FPSengine * FPS);  
Ui::fcpConfigForm ui;  
void setupFcpCfg();  

private:  
QWidget * myParent;  
FPSengine * myFPS;  

fcpCfgDelegate delegate;  
QList<QSpinBox*>failOrderList;  
QList<QRadioButton*>primaryList;  

int numFCP;  
QList<int>numFcpInEachSet;  
int currentSet;  

void updateSets();
void refreshFailorderDuringUserEdit(int fcpPos);
QSignalMapper * signalMapper;
QMutex mutex;
void sendSysStatusMsgAndPopup(QString msg);
int curSet;   //the connected Fcp's Set  

private slots:  

void updateFcpFailOrderSpinBox(int absPos);
void on_twFCP_cellClicked( int row, int column );
void on_buttonBox_clicked(QAbstractButton* button);

private:  
template <class T>  
    void buildObjList(QObject * location,QList<T> *cmdEleList,QString objName, int numObj){  
        T pCmdEle;  
        cmdEleList->clear();  
        for(int i=0;i<numObj;i++){  开发者_运维问答
            pCmdEle = location->findChild<T>(objName+QString("%1").arg(i+1));  
            cmdEleList->append(pCmdEle);  
        }  
    }  

//used to send SysStatus and popuMsg when number of active Fcps in Set not 1  
QString activeList;  //build a string representing Fcp numbers that are active.  
int iNumActive;  
};  
#endif // FCP_CONFIG_H


Different compilers do different things. The standard doesn't state that all variables should be initialized automatically, so many compilers don't. This means they are typically filled with garbage. Sometimes you luck out and get a block of zeros, but it's rare. Don't count on it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜