的C++截斷我得到這個警告恆定值
warning C4309: 'initializing' : truncation of constant value
,當我嘗試執行我的DLL只發送4個字節,而不是10個字節。
什麼可能是錯的?
這裏是我的代碼:
int WINAPI MySend(SOCKET s, const char* buf, int len, int flags)
{
cout << "[SEND:" << len << "] ";
for (int i = 0; i < len; i++) {
printf("%02x ", static_cast<unsigned char>(buf[i]));
}
printf("\n");
//causing the warning:
char storagepkt[] = {0x0A, 0x00, 0x01, 0x40, 0x79, 0xEA, 0x60, 0x1D, 0x6B, 0x3E};
buf = storagepkt;
len = sizeof(storagepkt);
return pSend(s, buf, len, flags);
}
UPDATE
int (WINAPI *pSend)(SOCKET s, const char* buf, int len, int flags) = send;
int WINAPI MySend(SOCKET s, const char* buf, int len, int flags);
UPDATE
件作爲建議我嘗試過的memcpy:
memcpy((char*) buf, storagepkt, sizeof(storagepkt));
UPDATE
unsigned char storagepkt[] = {0x0A, 0x00, 0x01, 0x40, 0x79, 0xEA, 0x60, 0x1D, 0x6B, 0x3E};
固定它。
該代碼調用'pSend()',但沒有出現。而是'MySend()'。是否有錯字或缺失? – wallyk
我正在使用彎路。都宣佈:) – madziikoy
@wallyk'pSend'正在從'MySend'裏面調用 –