[英]Newer version of GCC throws invalid conversion error
class FixedDataBlock: public DataBlockHeaderCommon<BlockSize>
{
// Construction
public:
FixedDataBlock(void* pool, SizeT const entrySize, SizeT const alignment)
: base_t(eBlkFixData, pool)
{
this_t* dummy = reinterpret_cast<this_t*>(0);
// offsets is a type of uint16_t
OffsetT dataStartBlockOffset = reinterpret_cast<OffsetT>( &dummy->data[0] );
}
// Member variables
private:
int8_t data[ BlockSize-sizeof(header_t) ];
};
error: invalid type conversion: "int8_t={signed char} *" to "uint16_t={unsigned short}" for line错误:无效的类型转换:“int8_t={signed char} *”到“uint16_t={unsigned short}”行
OffsetT dataStartBlockOffset = reinterpret_cast( &dummy->data[0] ); OffsetT dataStartBlockOffset = reinterpret_cast( &dummy->data[0] );
//dummy->data[0] is signed char* and dataStartBlockOffset is unsigned short //dummy->data[0] 是有符号的 char* 并且 dataStartBlockOffset 是无符号的 short
The above code is compiling fine on windows but it is failing only with the GCC.上面的代码在 Windows 上编译得很好,但它只在 GCC 上失败。
Using offsetof micro fixed compilation error.使用 offsetof 微修复编译错误。 OffsetT dataStartBlockOffset = (OffsetT)offsetof(FixedDataBlock, data);
OffsetT dataStartBlockOffset = (OffsetT)offsetof(FixedDataBlock, data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.