mercredi 30 mars 2016

std::aligned_union not working as I would expect

I am trying to simulate having a union with an int and a double as follows

int main() {

    union U { double d; int a; };
    std::aligned_union<8, int, double> buffer;
    cout << "Size of the union is " << sizeof(U) << endl;
    cout << "size of the buffer is " << sizeof(buffer) << endl;

    return 0;
}

But the output of the program is always that the size of the union is an 8 and the sizeof the aligned union is 1. Could someone explain how I am using this wrong?

Thanks!

Aucun commentaire:

Enregistrer un commentaire