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

yan*_*nce 3 c++ ubuntu qt gcc 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
Run Code Online (Sandbox Code Playgroud)


#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
Run Code Online (Sandbox Code Playgroud)

Jos*_*shD 10

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

  • 始终始终始终初始化变量.然后,即使您的代码不正确,至少它也是一致的. (6认同)
  • @yan该标准并未声明它必须是随机的. (2认同)