相关疑难解决方法(0)

Visual C++相当于GCC的__attribute __((__ package___))

对于某些编译器,有一个结构的打包说明符,例如::

RealView ARM compiler has "__packed"
Gnu C Compiler has "__attribute__ ((__packed__))"
Visual C++ has no equivalent, it only has the "#pragma pack(1)"

我需要一些我可以放入结构定义的东西.

任何信息/黑客/建议?TIA ...

c c++ gcc visual-c++ data-structures

46
推荐指数
5
解决办法
6万
查看次数

pragma pack(1)也不是__attribute __((aligned(1)))有效

我的代码过去常用,但现在结构大小突然是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打包结构?

pragma llvm pack xcode4

18
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

c++ ×1

data-structures ×1

gcc ×1

llvm ×1

pack ×1

pragma ×1

visual-c++ ×1

xcode4 ×1