Windows SDK contains a set of typedefs:
typedef long LONG;
typedef struct tagPOINT
{
LONG x;
LONG y;
} POINT;
typedef struct tagRECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
then, there's a WinAPI function that expects a pointer to an array of POINT
structs and the length of that array:
void ThatFunction( POINT* points, int numberOfElements );
and we have the following code:
RECT rect = ...//obtained from somewhere
ThatFunction( reinterpret_cast<POINT*>( &rect ), 2 );
so that RECT
is being treated as an array of two POINT
structures.
Is such cast safe?
Because the Windows developers declared RECT and POINT right next to each in WinDef.h with the same packing, you can pretty much assume that it is safe. The Win32 API, MapWindowPoints, is an example of a function that can be be passed a RECT or a pair of POINTs. The docs even suggest using it as such.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With