Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

union with eigen data types

I have been testing Eigen library datatypes with union for type punning. My intent is to have a single memory of double array that can be accessed as an eigen data type and vice versa.

example:

union BigBox{
    double X[13];
    struct
    {
        Eigen::Vector3d p;
        Eigen::Vector3d v;
        Eigen::Vector3d w;
        Eigen::Vector4d q;
    } data;

};

When I test the

sizeof(BigBox)/sizeof(double) = 14
sizeof(Eigen::Vector3d)/sizeof(double) = 3
sizeof(Eigen::Vector4d)/sizeof(double) = 4

The size of the struct does not add up. How does the extra +1 get allotted? I believe it could be because of the compiler trying to exploit the SMID features but is there any way for me to use type punning in these situations? What is the correct approach for what I am trying to achieve?

Comments