搞不定offsetof警告,改用指针,屏蔽sizeof隐式截断

This commit is contained in:
nnhy 2016-03-14 07:34:24 +00:00
parent c6bfa47be5
commit ef3dfcbda1
4 changed files with 12 additions and 4 deletions

View File

@ -177,8 +177,11 @@ typedef struct _TCP_HEADER
void Init(bool recursion = false)
{
#pragma GCC diagnostic ignored "-Woverflow"
Length = (byte)sizeof(this[0]);
//Length = (byte)0x14;
#pragma GCC diagnostic warning "-Woverflow"
reserved_1 = 0;
reserved_2 = 0;
//WindowSize = _REV16(8192);

View File

@ -43,7 +43,10 @@ void Device::Write(Stream& ms) const
{
TS("Device::Write");
/*#pragma GCC diagnostic ignored "-Winvalid-offsetof"
Buffer bs((void*)&Address, offsetof(Device, Cfg) - offsetof(Device, Address));
#pragma GCC diagnostic warning "-Winvalid-offsetof"*/
Buffer bs((void*)&Address, (byte*)&Cfg - (byte*)&Address);
ms.WriteArray(bs);
}
@ -52,7 +55,8 @@ void Device::Read(Stream& ms)
TS("Device::Read");
// 为了避免不同版本的配置兼容,指定长度避免覆盖过头
Buffer bs(&Address, offsetof(Device, Cfg) - offsetof(Device, Address));
//Buffer bs(&Address, offsetof(Device, Cfg) - offsetof(Device, Address));
Buffer bs(&Address, (byte*)&Cfg - (byte*)&Address);
//bs = ms.ReadArray();
// 为了减少一个临时对象,直接传入外部包装给内部拷贝
uint len = ms.ReadEncodeInt();

View File

@ -538,8 +538,9 @@ TokenStat::TokenStat()
_Last = nullptr;
_Total = nullptr;*/
int start = offsetof(TokenStat, SendRequest);
Buffer((byte*)this + start, sizeof(TokenStat) - start).Clear();
/*int start = offsetof(TokenStat, SendRequest);
Buffer((byte*)this + start, sizeof(TokenStat) - start).Clear();*/
Buffer(&SendRequest, (byte*)&WriteReply + sizeof(WriteReply) - (byte*)&SendRequest).Clear();
}
TokenStat::~TokenStat()

View File

@ -693,7 +693,7 @@ namespace NewLife.Reflection
private String GetObjPath(String file)
{
var objName = "Obj";
var objName = "Gcc";
if (Tiny)
objName += "T";
else if (Debug)