Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Apple GCC 4.2.1将指针传递给构造函数_C++_Alignment - Fatal编程技术网

C++ Apple GCC 4.2.1将指针传递给构造函数

C++ Apple GCC 4.2.1将指针传递给构造函数,c++,alignment,C++,Alignment,假设我有一个类,它或它的成员没有明显的问题,但是如果我尝试将几个类成员的地址传递给同一模块中的另一个类,第一个参数传递正确,但第二个参数总是NULL!这怎么可能?是否存在某种隐藏的堆栈/堆损坏或某种对齐问题?MSVC中没有问题,不过 class myType2 { char c1; char c2; } __attribute__ ((aligned (1))); // Yes, align differs and I can't change it class MyCla

假设我有一个类,它或它的成员没有明显的问题,但是如果我尝试将几个类成员的地址传递给同一模块中的另一个类,第一个参数传递正确,但第二个参数总是NULL!这怎么可能?是否存在某种隐藏的堆栈/堆损坏或某种对齐问题?MSVC中没有问题,不过

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!!!
    }
} __attribute__ ((aligned (16)));

该死的GCC…:doubleFacePalm我无法正常解决此问题,但我找到了一个解决方法,通过在一个按16字节边界对齐的结构中传递所有类构造函数数据。

在带有gcc 4.0的ppc mac中适用。你能给出一个完整的例子来说明这个问题吗?是的,简化的例子总是很好用的。我无法向您展示一个完整的示例,因为它有数十万行代码…我尝试了很多变化,但似乎无论我传递什么类型的数据,只有第一个参数是正确传递的。。。stack肯定有问题:(那么我们应该如何找到您的问题?好吧,也许有人遇到过这种问题,可以给我一些建议?也许数据有某种限制,可以在GCC或类似的东西中在stack上传递?