对于某些编译器,有一个结构的打包说明符,例如::
RealView ARM compiler has "__packed" Gnu C Compiler has "__attribute__ ((__packed__))" Visual C++ has no equivalent, it only has the "#pragma pack(1)"
我需要一些我可以放入结构定义的东西.
任何信息/黑客/建议?TIA ...
我的代码过去常用,但现在结构大小突然是16个字节.它曾经是13个字节.我最近从Xcode 4.2升级到Xcode 4.3.1(4E1019).
#pragma pack(1)
struct ChunkStruct {
uint32_t width;
uint32_t height;
uint8_t bit_depth;
uint8_t color_type;
uint8_t compression;
uint8_t filter;
uint8_t interlace;
};
#pragma pack()
STATIC_ASSERT(expected_13bytes, sizeof(struct ChunkStruct) == 13);
Run Code Online (Sandbox Code Playgroud)
我试过不成功的使用
#pragma pack(push, 1)
/* struct ChunkStruct { ... }; */
#pragma pack(pop)
Run Code Online (Sandbox Code Playgroud)
我也试过以下,但没有运气
struct ChunkStruct {
uint32_t width;
uint32_t height;
uint8_t bit_depth;
uint8_t color_type;
uint8_t compression;
uint8_t filter;
uint8_t interlace;
} __attribute__ ((aligned (1)));
Run Code Online (Sandbox Code Playgroud)
如何用Xcode 4.3.1打包结构?