简体   繁体   English

C ++生成警告:取消引用类型标记的指针将破坏严格的别名规则

[英]C++ build warning : dereferencing type-punned pointer will break strict-aliasing rules

I have this warning on my cast line code: 我在强制转换代码中有此警告:

dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict- aliasing] 取消引用类型化指针将破坏严格别名规则[-Wstrict-alias]

unsigned char buffer[64];
...
unsigned int value = *(unsigned int*)buffer;

How to fix this warning ? 如何解决此警告?

Thanks for your help ! 谢谢你的帮助 !

What this code does depends on the platform's endianness, alignment rules, integer size, and other things. 该代码的作用取决于平台的字节序,对齐规则,整数大小以及其他因素。 There's no way to know what it does just by looking at it. 仅通过查看就无法知道它的作用。 But you probably want something like this: 但是您可能想要这样的东西:

unsigned int value = buffer[0];
value = (value << 8) | buffer[1];
value = (value << 8) | buffer[2];
value = (value << 8) | buffer[3];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告! 取消引用类型化指针会破坏严格混叠规则[-Wstrict-aliasing] - warning! dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] “解除引用类型惩罚指针将破坏严格别名规则”警告 - “dereferencing type-punned pointer will break strict-aliasing rules” warning GCC警告“解除引用类型 - 惩罚指针将破坏严格别名规则” - GCC warning “dereferencing type-punned pointer will break strict-aliasing rules” 警告的正确修复:取消引用类型双关指针会破坏严格的别名规则? - correct fix for warning: dereferencing type-punned pointer will break strict-aliasing rules? stof()/ stoi()带有解引用类型指针的指针将破坏严格的混叠规则 - stof()/stoi() with dereferencing type-punned pointer will break strict-aliasing rules GCC 7,aligned_storage和“解除引用类型惩罚指针将破坏严格别名规则” - GCC 7, aligned_storage and “dereferencing type-punned pointer will break strict-aliasing rules” 将char []强制转换为usigned int可以得到:取消引用类型标记的指针将破坏严格的别名规则 - Casting char[] to usigned int gives: dereferencing type-punned pointer will break strict-aliasing rules 取消引用类型标记的指针将破坏严格的别名规则:将字节数组转换为数字 - dereferencing type-punned pointer will break strict-aliasing rules: array of bytes to a number Float64 位问题冷杉取消引用类型双关指针将破坏严格别名规则 [-Wstrict-aliasing] - Float64 bit issue fir dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 奇怪的C ++严格别名警告 - Odd C++ strict-aliasing warning
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM