[英]“cast from 'uint8_t*' to 'uint16_t' loses precision” when compiling for STM32
I'm trying to port out the Arduino Ethernet library to libmaple
for use with STM32 devices. 我正在尝试将Arduino以太网库
libmaple
到libmaple
以便与STM32设备一起使用。 When compiling (using the CodeSourcery GCC toolchain). 编译时(使用CodeSourcery GCC工具链)。 I get
我懂了
libraries/Ethernet/w5100.cpp:111: error: cast from 'uint8_t*' to 'uint16_t' loses precision
around the code segment: 在代码段周围:
void W5100Class::read_data(SOCKET s, uint8_t *src, uint8_t *dst, uint16_t len)
{
uint16_t size;
uint16_t src_ptr;
src_mask = (uint16_t)src & RMASK;
src_ptr = RBASE[s] + src_mask;
if( (src_mask + len) > RSIZE )
{
size = RSIZE - src_mask;
read(src_ptr, (uint8_t *)dst, size);
dst += size;
read(RBASE[s], (uint8_t *) dst, len - size);
}
else
read(src_ptr, (uint8_t *) dst, len);
}
您的指针类型是32位,因此当您尝试将其分配给16位时,它将丢失数据。
Change src_mask = (uint16_t)src & RMASK;
更改
src_mask = (uint16_t)src & RMASK;
to src_mask = (0xffff & src) & RMASK;
到
src_mask = (0xffff & src) & RMASK;
will meet your demand too. 也将满足您的需求。 Just discard higher 16 bits as you wish.
只需丢弃高16位即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.