为什么我'__packed__' attribute ignored [-Wattributes]
在 android NDK 项目中收到警告?
这是代码
mem_ = malloc(size_);
uint8_t* ui8_ptr = reinterpret_cast<uint8_t*>(mem_);
*ui8_ptr++ = packet_version;
//uint32_t* ui32_ptr = reinterpret_cast<uint32_t*>(ui8_ptr);
__packed uint32_t* ui32_ptr = (__packed uint32_t*)(ui8_ptr);
*ui32_ptr++ = size_;
*ui32_ptr++ = flags;
我使用了 packed 属性,因为我认为从 uint8_t 转换为 uint32_t 时存在对齐问题(参见 [1])。
[1] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka15414.html