MW compiler class member (struct) initialization

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

MW compiler class member (struct) initialization

跳至解决方案
625 次查看
juhalaukkanen
Contributor III

Hello.

Following test code compiled with Metrowerks compiler doesn't initialize Test2 struct members member1 and member2 to 0. GCC does however generate default initializer for Test2 that initializes all inside the struct to zero. GCC does that in all cases how class is instantiated but MW doesn't do in any case. To me this seems a bit odd. Am I missing some compiler flag which would do this?

Used flags are -proc e500v2 -cwd proj -ipa off -fp dpfp -spe_vector -norelax_ieee -char unsigned -use_lmw_stmw on -w all -w err -lang c++ -RTTI off

GCC version is 4.8.2 (gcc-4.8.2-Ee500v2-eabispe) and MW compiler is 4.3 build 278. Both supplied with CW 10.4.

class TestClass

{

public:

    TestClass();

    TestClass(char max);

    void fun1();

private:

    long*        m_data;

    struct Test2

    {

        unsigned short member1;

        unsigned short member2;

        /*Test2()

        {

            member1 = member2 = 0;

        }*/

    } m_str1;

    char             m_pp1;

    char             m_pp2;

};

TestClass::TestClass() :

    m_str1(),

    m_data(0)

{

}

TestClass::TestClass(char max) :

    m_data(0),

    m_pp2(),

    m_str1(),

    m_pp1(max)

{

    for (char i = 0; i < m_pp1; ++i)

    {

        m_data++;

    }

}

void TestClass::fun1()

{

    while (m_str1.member1 && m_str1.member2)

    {

        m_data++;

    }

}

void tester();

void tester()

{

    TestClass tTemp1(9);

    TestClass tTemp2;

    TestClass *tTemp3 = new TestClass;

    TestClass *tTemp4 = new TestClass(42);

    tTemp1.fun1();

    tTemp2.fun1();

    tTemp3->fun1();

    tTemp4->fun1();

}

标签 (2)
标记 (4)
0 项奖励
1 解答
420 次查看
marius_grigoras
NXP Employee
NXP Employee

Hi,

Thank you for your research, you're not missing any MW compiler flag and indeed, there is a bug in our MW compiler. I'll discuss with our compiler team and will be fixed.

Regards,

Marius

在原帖中查看解决方案

1 回复
421 次查看
marius_grigoras
NXP Employee
NXP Employee

Hi,

Thank you for your research, you're not missing any MW compiler flag and indeed, there is a bug in our MW compiler. I'll discuss with our compiler team and will be fixed.

Regards,

Marius