可疑的指针到指针转换(面积太小) [英] Suspicious pointer-to-pointer conversion (area too small)
问题描述
我收到此警告是出于我的逻辑-
I am getting this warning for my logic -
逻辑:
uint8_t *m_data;
uint32_t* datap = (uint32_t*)m_data;
警告:
Info 826: Suspicious pointer-to-pointer conversion (area too small)
由于需要在赋值期间进行类型转换..而且我没有感觉到给定代码行中有问题..我如何抑制此警告或将其从构建中删除
As it is required to typecast the value during assignment ..And i am not feeling there is something wrong in given line of code ..how I can suppress this warning or remove it from build
推荐答案
这不是正确的强制转换,您试图将指向某个字节的指针解释为指向4个字节的指针,并可能导致意外结果.如果uint32_t
与uint8_t
具有不同的对齐要求,则您甚至可能获得不同的指针值以及指向的指针.如果要转换值,请执行以下操作:
That's not a correct cast, you're attempting to interpret a pointer to a byte as a pointer to 4 bytes, and can lead to unexpected results. If uint32_t
has different alignment requirements than uint8_t
, you might even get a different value of the pointer, and also what it points to. If you want to convert the value, just do:
uint32_t datap;
datap = static_cast<uint32_t>(*m_data);
这篇关于可疑的指针到指针转换(面积太小)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!