不对齐警告修复它们或不修复它们?

use*_*108 -1 c++ memory-alignment type-punning

在我的自定义.zip解压缩器中,我得到这样的警告:

runtime error: load of misaligned address 0x7f280ffe875a for type 'const uint32_t', which requires 4 byte alignment
Run Code Online (Sandbox Code Playgroud)

究其原因是reinterpret_castuint32_t*和相同的解引用.我知道,memcpyuint32_t会解决这个问题,但我要这么做?我看到许多广泛使用的库(如pixman,cairo ......)都有同样的警告.

oct*_*oid 5

总是修理它们.编译器的矢量化程序可能使用对齐信息,并假定您不调用未定义的行为.这可能导致崩溃.

有关gcc devs和LZ4作者之间关于此问题的讨论,请参阅:https://gcc.gnu.org/bugzilla/show_bug.cgi?id = 65709.