struct Point
{
double X;
double Y;
};
Q1) is the following portable (compilers / machines)
Point point = { 1.1, 2.2 };
double arr[2] = {};
memcpy(arr, point, sizeof(double)*2);
Q2) same for array of struct
Point *pPoints = new Point[numPoints];
double *pArr = new double[2*numPoints];
memcpy(pArr, pPoints, sizeof(double)*2*numPoints);
on Windows/MSVC I'm expecting both to succeed.
EDIT: I'm not asking these questions for every possible structs/classes; I'm asking for this particular case of struct "Point" (notice : only 2 pods, no virtualmember / user constructor/user desctructor). This might as well be a C question it has to do with struct alignment and memory layout accross compilers.
So far I've got that the c/c++ standard doesn't enforce anything for the layout of Point so I must ensure it myself with a static assert, correct ?