开发者

Apple GCC 4.2.1 passing a pointer to constructor

Let's say I have a class and there are no visible problems with it or its members, however if I try to pass the addresses of several class members to another class in the same module, the first argument is being passed correctly, but the second one is always NULL! How can this be? Could there be some kind of hidden stack / heap corruption or some kind of alignment problem? There are no problems in MSVC, though...

class myType2
{
     char c1;
     char c2;
} __attribute__ ((aligned (1))); // Yes, align differs and I can't change it

class MyClass2
{
public:
    MyClass2(myType1* type1, myType2* type2, int data)
    {
         // type1 and data are ok, but type2 is NULL...
    }
} __attribute__ ((aligned (16)));

class MyClass
{
public:
    myType1 type1;
    myType2 type2;
    //....
    void test()
    {
        MyClass2 test1(&this->type1, &this->type2, 170);
        MyClass2* pTest2 = new MyClass2(&this->type1, &this->type2, 170); // Same result

        myType2 localType2;
        MyClass2 test3(&this->type1, &localType2, 170); // Same result!!!
    }
} 开发者_C百科__attribute__ ((aligned (16)));


Blasted GCC... :doubleFacePalm I wasn't able to solve this problem normally, but I found a workaround by passing all class constructor data in a structure aligned by 16 bytes boundary.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜