【发布时间】:2011-01-31 08:34:48
【问题描述】:
Windows SDK 包含一组 typedef:
typedef long LONG;
typedef struct tagPOINT
{
LONG x;
LONG y;
} POINT;
typedef struct tagRECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
然后,有一个 WinAPI 函数需要一个指向 POINT 结构数组的指针和该数组的长度:
void ThatFunction( POINT* points, int numberOfElements );
我们有以下代码:
RECT rect = ...//obtained from somewhere
ThatFunction( reinterpret_cast<POINT*>( &rect ), 2 );
因此RECT 被视为两个POINT 结构的数组。
这样的演员表安全吗?
【问题讨论】:
标签: c++ windows winapi visual-c++ casting