在某些平台上,可变初始化不会发生

时间:2010-10-08 23:46:57

标签: c++ qt gcc ubuntu redhat

我有一个为RHEL5 32位和ubuntu10 64位(c ++ qt4.6)构建的程序。当我在ubuntu上运行程序时,所有变量都被初始化,而我不需要对这个初始化进行编码。但是当我在RHEL上运行程序时,一些变量没有被初始化,我注意到它们大多是整数类型,并且典型值大约是154280152.有趣的是它只发生在几个类中。怎么会这样?

更新:这里是一段代码,它是其中一个类的标题(对不起我现在正在研究的布局):
#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

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

1 个答案:

答案 0 :(得分:10)

不同的编译器会做不同的事情。 标准没有说明所有变量都应该自动初始化,所以很多编译器都没有。这意味着它们通常充满了垃圾。有时你运气好,并获得一块零,但这很少见。不要指望它。