R
rajkumar
hey all
While maintaining some legacy code I came across such a class
class Point
{
double coordinate[3];
};
This class doesn't have any virtual functions and is aligned by
default without any padding bits such that sizeof(Point)=
3*sizeof(double).
In several places a pointer to this class is interchangebly used as
double array of size 3. Is this undefined behaviour ? Even if it is I
guess I can fix by defining double* operator and making sure Point* is
not used as double* and Point is used as double*
Also huge arrays of Points are passed as 3 * array of doubles to
other functions that expect double arrays? Is this legal according to
standard ? If so, can this made legal without actually making a copy ?
Any reference to the standard would be greatly appreciated.
Thanks
Raj
While maintaining some legacy code I came across such a class
class Point
{
double coordinate[3];
};
This class doesn't have any virtual functions and is aligned by
default without any padding bits such that sizeof(Point)=
3*sizeof(double).
In several places a pointer to this class is interchangebly used as
double array of size 3. Is this undefined behaviour ? Even if it is I
guess I can fix by defining double* operator and making sure Point* is
not used as double* and Point is used as double*
Also huge arrays of Points are passed as 3 * array of doubles to
other functions that expect double arrays? Is this legal according to
standard ? If so, can this made legal without actually making a copy ?
Any reference to the standard would be greatly appreciated.
Thanks
Raj